You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/23 11:38:09 UTC
[01/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Repository: incubator-taverna-plugin-bioinformatics
Updated Branches:
refs/heads/master e13e3b741 -> 87883d91b
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivity.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivity.java b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivity.java
new file mode 100644
index 0000000..53091e1
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivity.java
@@ -0,0 +1,413 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ServiceException;
+
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.log4j.Logger;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * An Activity providing Soaplab functionality.
+ *
+ * @author David Withers
+ */
+public class SoaplabActivity extends AbstractAsynchronousActivity<JsonNode> {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/soaplab";
+
+ private static final Logger logger = Logger
+ .getLogger(SoaplabActivity.class);
+
+ private static final int INVOCATION_TIMEOUT = 0;
+
+ private JsonNode json;
+
+// private Map<String, Class<?>> inputTypeMap = new HashMap<String, Class<?>>();
+
+ public SoaplabActivity() {
+ }
+
+ @Override
+ public void configure(JsonNode configurationBean) throws ActivityConfigurationException {
+ this.json = configurationBean;
+// generatePorts();
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return json;
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ @SuppressWarnings("unchecked")
+ public void run() {
+ ReferenceService referenceService = callback.getContext().getReferenceService();
+
+ Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();
+
+ try {
+ // Copy the contents of the data set in the input map
+ // to a new Map object which just contains the raw data
+ // objects
+ Map<String, Object> soaplabInputMap = new HashMap<String, Object>();
+ for (Map.Entry<String, T2Reference> entry : data
+ .entrySet()) {
+ Class<?> inputType = getInputType(entry.getKey());
+ logger.info("Resolving " + entry.getKey() + " to "
+ + inputType);
+ soaplabInputMap.put(entry.getKey(), referenceService.renderIdentifier(
+ entry.getValue(), inputType, callback.getContext()));
+ logger.info(" Value = "
+ + soaplabInputMap.get(entry.getKey()));
+ }
+
+ // Invoke the web service...
+ Call call = (Call) new Service().createCall();
+ call.setTimeout(new Integer(INVOCATION_TIMEOUT));
+ // TODO is there endpoint stored in the configuration as a
+ // String or a URL?
+ // URL soaplabWSDLURL = new
+ // URL(configurationBean.getEndpoint());
+ call.setTargetEndpointAddress(json.get("endpoint").textValue());
+
+ // Invoke the job and wait for it to complete
+ call.setOperationName(new QName("createAndRun"));
+ String jobID = (String) call
+ .invoke(new Object[] { soaplabInputMap });
+ // Get the array of desired outputs to avoid pulling
+ // everything back
+ // TODO Decide how to get the bound ports for the processor
+ // OutputPort[] boundOutputs =
+ // this.proc.getBoundOutputPorts();
+ OutputPort[] boundOutputs = getOutputPorts().toArray(
+ new OutputPort[0]);
+ String[] outputPortNames = new String[boundOutputs.length];
+ for (int i = 0; i < outputPortNames.length; i++) {
+ outputPortNames[i] = boundOutputs[i].getName();
+ logger.debug("Adding output : " + outputPortNames[i]);
+ }
+
+ if (!isPollingDefined()) {
+ // If we're not polling then use this behaviour
+ call.setOperationName(new QName("waitFor"));
+ call.invoke(new Object[] { jobID });
+ } else {
+ // Wait for the polling interval then request a status
+ // and do this until the status is terminal.
+ boolean polling = true;
+ // Number of milliseconds to wait before the first
+ // status request.
+ int pollingInterval = json.get("pollingInterval").intValue();
+ while (polling) {
+ try {
+ Thread.sleep(pollingInterval);
+ } catch (InterruptedException ie) {
+ // do nothing
+ }
+ call.setOperationName(new QName("getStatus"));
+ String statusString = (String) call
+ .invoke(new Object[] { jobID });
+ logger.info("Polling, status is : " + statusString);
+ if (statusString.equals("RUNNING")
+ || statusString.equals("CREATED")) {
+ pollingInterval = (int) ((double) pollingInterval * json
+ .get("pollingBackoff").doubleValue());
+ if (pollingInterval > json.get("pollingIntervalMax").intValue()) {
+ pollingInterval = json.get("pollingIntervalMax").intValue();
+ }
+ } else {
+ // Either completed with an error or success
+ polling = false;
+ }
+ }
+ }
+
+ // Get the status code
+ call.setOperationName(new QName("getStatus"));
+ String statusString = (String) call
+ .invoke(new Object[] { jobID });
+ if (statusString.equals("TERMINATED_BY_ERROR")) {
+ // Get the report
+ call.setOperationName(new QName("getSomeResults"));
+ HashMap<String, String> temp = new HashMap<String, String>(
+ (Map) call.invoke(new Object[] { jobID,
+ new String[] { "report" } }));
+ String reportText = temp.get("report");
+ callback.fail("Soaplab call returned an error : "
+ + reportText);
+ return;
+ }
+
+ // Get the results required by downstream processors
+ call.setOperationName(new QName("getSomeResults"));
+ HashMap<String, Object> outputMap = new HashMap<String, Object>(
+ (Map) call.invoke(new Object[] { jobID,
+ outputPortNames }));
+
+ // Tell soaplab that we don't need this session any more
+ call.setOperationName(new QName("destroy"));
+ call.invoke(new Object[] { jobID });
+
+ // Build the map of DataThing objects
+ for (Map.Entry<String, Object> entry : outputMap.entrySet()) {
+ String parameterName = entry.getKey();
+ Object outputObject = entry.getValue();
+ if (logger.isDebugEnabled())
+ logger.debug("Soaplab : parameter '"
+ + parameterName + "' has type '"
+ + outputObject.getClass().getName() + "'");
+
+ if (outputObject instanceof String[]) {
+ // outputThing = DataThingFactory
+ // .bake((String[]) outputObject);
+ outputData.put(parameterName, referenceService
+ .register(Arrays.asList(outputObject), 1, true, callback.getContext()));
+ } else if (outputObject instanceof byte[][]) {
+ // Create a List of byte arrays, this will
+ // map to l('application/octet-stream') in
+ // the output document.
+ // outputThing = DataThingFactory
+ // .bake((byte[][]) outputObject);
+ List<byte[]> list = new ArrayList<byte[]>();
+ for (byte[] byteArray : (byte[][]) outputObject) {
+ list.add(byteArray);
+ }
+ outputData.put(parameterName, referenceService
+ .register(list, 1, true, callback.getContext()));
+ // outputData.put(parameterName, dataFacade
+ // .register(Arrays.asList(outputObject)));
+ } else if (outputObject instanceof List) {
+ List<?> convertedList = convertList((List<?>) outputObject);
+ outputData.put(parameterName, referenceService
+ .register(convertedList, 1, true, callback.getContext()));
+ } else {
+ // Fallthrough case, this mostly applies to
+ // output of type byte[] or string, both of which
+ // are handled perfectly sensibly by default.
+ outputData.put(parameterName, referenceService
+ .register(outputObject, 0, true, callback.getContext()));
+ }
+ }
+
+ // success
+ callback.receiveResult(outputData, new int[0]);
+ } catch (ReferenceServiceException e) {
+ callback.fail("Error accessing soaplab input/output data", e);
+ } catch (IOException e) {
+ callback.fail("Failure calling soaplab", e);
+ } catch (ServiceException e) {
+ callback.fail("Failure calling soaplab", e);
+ }
+ }
+
+ });
+
+ }
+
+ public boolean isPollingDefined() {
+ return json != null
+ && (json.get("pollingInterval").intValue() != 0
+ || json.get("pollingBackoff").doubleValue() != 1.0 || json
+ .get("pollingIntervalMax").intValue() != 0);
+ }
+
+ private List<?> convertList(List<?> theList) {
+ if (theList.size() == 0) {
+ return theList;
+ }
+
+ List<byte[]> listOfBytes = new ArrayList<byte[]>();
+ for (Object element : theList) {
+ if (element instanceof List) {
+ List<?> list = ((List<?>) element);
+ if (list.size() > 0 && (list.get(0) instanceof Byte)) {
+ byte[] bytes = new byte[list.size()];
+ for (int j = 0; j < list.size(); j++) {
+ bytes[j] = ((Byte) list.get(j)).byteValue();
+ }
+ listOfBytes.add(bytes);
+ } else {
+ // If we can't cope here just return the original
+ // object
+ return theList;
+ }
+ } else {
+ return theList;
+ }
+ }
+ return listOfBytes;
+ }
+
+ private Class<?> getInputType(String portName) {
+ Class<?> inputType = String.class;
+ for (ActivityInputPort inputPort : getInputPorts()) {
+ if (inputPort.getName().equals(portName)) {
+ return inputPort.getTranslatedElementClass();
+ }
+ }
+ return inputType;
+ }
+
+// @SuppressWarnings("unchecked")
+// private void generatePorts() throws ActivityConfigurationException {
+// // Wipe the existing port declarations
+// // ports = new ArrayList();
+// try {
+// // Do web service type stuff[tm]
+// Map<String, String>[] inputs = (Map<String, String>[]) Soap
+// .callWebService(json.get("endpoint").textValue(),
+// "getInputSpec");
+// // Iterate over the inputs
+// for (int i = 0; i < inputs.length; i++) {
+// Map<String, String> input_spec = inputs[i];
+// String input_name = input_spec.get("name");
+// String input_type = input_spec.get("type").toLowerCase();
+// // Could get other properties such as defaults here
+// // but at the moment we've got nowhere to put them
+// // so we don't bother.
+// if (input_type.equals("string")) {
+// addInput(input_name, 0, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(), String.class);
+// inputTypeMap.put(input_name, String.class);
+// } else if (input_type.equals("string[]")) {
+// addInput(input_name, 1, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(), String.class);
+// inputTypeMap.put(input_name, String.class);
+// } else if (input_type.equals("byte[]")) {
+// addInput(input_name, 0, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(), byte[].class);
+// inputTypeMap.put(input_name, byte[].class);
+// } else if (input_type.equals("byte[][]")) {
+// addInput(input_name, 1, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(), byte[].class);
+// inputTypeMap.put(input_name, byte[].class);
+// } else {
+// // Count number of [] to get the arrays right
+// int depth = (input_type.split("\\[\\]", -1).length) -1 ;
+// logger.info("Soaplab input type '" + input_type
+// + "' unknown for input '" + input_name + "' in "
+// + json.get("endpoint").textValue()
+// + ", will attempt to add as String depth " + depth);
+// addInput(input_name, depth, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(), String.class);
+// inputTypeMap.put(input_name, String.class);
+// }
+// }
+//
+// // Get outputs
+// Map<String, String>[] results = (Map<String, String>[]) Soap
+// .callWebService(json.get("endpoint").textValue(),
+// "getResultSpec");
+// // Iterate over the outputs
+// for (int i = 0; i < results.length; i++) {
+// Map<String, String> output_spec = results[i];
+// String output_name = output_spec.get("name");
+// String output_type = output_spec.get("type").toLowerCase();
+// // Check to see whether the output is either report or
+// // detailed_status, in
+// // which cases we ignore it, this is soaplab metadata rather
+// // than application data.
+// if ((!output_name.equalsIgnoreCase("detailed_status"))) {
+//
+// // && (!output_name.equalsIgnoreCase("report"))) {
+// if (output_type.equals("string")) {
+// addOutput(output_name, 0, "text/plain");
+// } else if (output_type.equals("string[]")) {
+// addOutput(output_name, 1, "text/plain");
+// } else if (output_type.equals("byte[]")) {
+// addOutput(output_name, 0, "application/octet-stream");
+// } else if (output_type.equals("byte[][]")) {
+// addOutput(output_name, 1, "application/octet-stream");
+// } else {
+// // Count number of [] to get the arrays right
+// int depth = (output_type.split("\\[\\]", -1).length) -1 ;
+// logger.info("Soaplab output type '" + output_type
+// + "' unknown for output '" + output_name + "' in "
+// + json.get("endpoint").textValue()
+// + ", will add as depth " + depth);
+// addOutput(output_name, depth, null);
+// }
+// }
+// }
+//
+// } catch (ServiceException se) {
+// throw new ActivityConfigurationException(
+// json.get("endpoint").textValue()
+// + ": Unable to create a new call to connect\n to soaplab, error was : "
+// + se.getMessage());
+// } catch (RemoteException re) {
+// throw new ActivityConfigurationException(
+// ": Unable to call the get spec method for\n endpoint : "
+// + json.get("endpoint").textValue()
+// + "\n Remote exception message "
+// + re.getMessage());
+// } catch (NullPointerException npe) {
+// // If we had a null pointer exception, go around again - this is a
+// // bug somewhere between axis and soaplab
+// // that occasionally causes NPEs to happen in the first call or two
+// // to a given soaplab installation. It also
+// // manifests in the Talisman soaplab clients.
+// generatePorts();
+// }
+// }
+
+// protected void addOutput(String portName, int portDepth, String type) {
+// ActivityOutputPort port = edits.createActivityOutputPort(
+// portName, portDepth, portDepth);
+// MimeType mimeType = null;
+// if (type != null) {
+// mimeType = new MimeType();
+// mimeType.setText(type);
+// }
+// try {
+// edits.getAddAnnotationChainEdit(port, mimeType).doEdit();
+// } catch (EditException e) {
+// logger.debug("Error adding MimeType annotation to port", e);
+// }
+// outputPorts.add(port);
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBean.java b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBean.java
new file mode 100644
index 0000000..fa6bdec
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBean.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A configuration bean specific to a Soaplab activity. In particular it provides details
+ * about the Soaplab service endpoint and the polling settings.
+ *
+ * @author David Withers
+ */
+@ConfigurationBean(uri = SoaplabActivity.URI + "#Config")
+public class SoaplabActivityConfigurationBean {
+
+ private String endpoint = null;
+
+ private int pollingInterval = 0;
+
+ private double pollingBackoff = 1.0;
+
+ private int pollingIntervalMax = 0;
+
+ /**
+ * Returns the endpoint.
+ *
+ * @return the endpoint
+ */
+ public String getEndpoint() {
+ return endpoint;
+ }
+
+ /**
+ * Sets the endpoint.
+ *
+ * @param endpoint the new endpoint
+ */
+ @ConfigurationProperty(name = "endpoint", label = "Soaplab Service Endpoint", description = "The endpoint of the Soaplab service")
+ public void setEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ /**
+ * Returns the pollingInterval.
+ *
+ * @return the pollingInterval
+ */
+ public int getPollingInterval() {
+ return pollingInterval;
+ }
+
+ /**
+ * Sets the pollingInterval.
+ *
+ * @param pollingInterval the new pollingInterval
+ */
+ @ConfigurationProperty(name = "pollingInterval", label = "Polling Interval", description = "The polling time interval (in milliseconds)", required = false)
+ public void setPollingInterval(int pollingInterval) {
+ this.pollingInterval = pollingInterval;
+ }
+
+ /**
+ * Returns the pollingBackoff.
+ *
+ * @return the pollingBackoff
+ */
+ public double getPollingBackoff() {
+ return pollingBackoff;
+ }
+
+ /**
+ * Sets the pollingBackoff.
+ *
+ * @param pollingBackoff the new pollingBackoff
+ */
+ @ConfigurationProperty(name = "pollingBackoff", label = "Polling Backoff", description = "The polling backoff factor", required = false)
+ public void setPollingBackoff(double pollingBackoff) {
+ this.pollingBackoff = pollingBackoff;
+ }
+
+ /**
+ * Returns the pollingIntervalMax.
+ *
+ * @return the pollingIntervalMax
+ */
+ public int getPollingIntervalMax() {
+ return pollingIntervalMax;
+ }
+
+ /**
+ * Sets the pollingIntervalMax.
+ *
+ * @param pollingIntervalMax the new pollingIntervalMax
+ */
+ @ConfigurationProperty(name = "pollingIntervalMax", label = "Max Polling Interval", description = "The maximum polling time interval (in milliseconds)", required = false)
+ public void setPollingIntervalMax(int pollingIntervalMax) {
+ this.pollingIntervalMax = pollingIntervalMax;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityFactory.java b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityFactory.java
new file mode 100644
index 0000000..3c62c9d
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityFactory.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import java.io.IOException;
+import java.net.URI;
+import java.rmi.RemoteException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.rpc.ServiceException;
+
+import net.sf.taverna.t2.annotation.annotationbeans.MimeType;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+import org.apache.log4j.Logger;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * An {@link ActivityFactory} for creating <code>SoaplabActivity</code>.
+ *
+ * @author David Withers
+ */
+public class SoaplabActivityFactory implements ActivityFactory {
+
+ private static final Logger logger = Logger.getLogger(SoaplabActivityFactory.class);
+
+ private Edits edits;
+
+ @Override
+ public SoaplabActivity createActivity() {
+ return new SoaplabActivity();
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(SoaplabActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode json) throws ActivityConfigurationException {
+ Set<ActivityInputPort> inputPorts = new HashSet<>();
+ try {
+ // Do web service type stuff[tm]
+ Map<String, String>[] inputs = (Map<String, String>[]) Soap
+ .callWebService(json.get("endpoint").textValue(),
+ "getInputSpec");
+ // Iterate over the inputs
+ for (int i = 0; i < inputs.length; i++) {
+ Map<String, String> input_spec = inputs[i];
+ String input_name = input_spec.get("name");
+ String input_type = input_spec.get("type").toLowerCase();
+ // Could get other properties such as defaults here
+ // but at the moment we've got nowhere to put them
+ // so we don't bother.
+ if (input_type.equals("string")) {
+ inputPorts.add(edits.createActivityInputPort(input_name, 0, true,
+ null, String.class));
+ } else if (input_type.equals("string[]")) {
+ inputPorts.add(edits.createActivityInputPort(input_name, 1, true,
+ null, String.class));
+ } else if (input_type.equals("byte[]")) {
+ inputPorts.add(edits.createActivityInputPort(input_name, 0, true,
+ null, byte[].class));
+ } else if (input_type.equals("byte[][]")) {
+ inputPorts.add(edits.createActivityInputPort(input_name, 1, true,
+ null, byte[].class));
+ } else {
+ // Count number of [] to get the arrays right
+ int depth = (input_type.split("\\[\\]", -1).length) -1 ;
+ logger.info("Soaplab input type '" + input_type
+ + "' unknown for input '" + input_name + "' in "
+ + json.get("endpoint").textValue()
+ + ", will attempt to add as String depth " + depth);
+ inputPorts.add(edits.createActivityInputPort(input_name, depth, true, null, String.class));
+ }
+ }
+ } catch (ServiceException se) {
+ throw new ActivityConfigurationException(
+ json.get("endpoint").textValue()
+ + ": Unable to create a new call to connect\n to soaplab, error was : "
+ + se.getMessage());
+ } catch (RemoteException re) {
+ throw new ActivityConfigurationException(
+ ": Unable to call the get spec method for\n endpoint : "
+ + json.get("endpoint").textValue()
+ + "\n Remote exception message "
+ + re.getMessage());
+ } catch (NullPointerException npe) {
+ // If we had a null pointer exception, go around again - this is a
+ // bug somewhere between axis and soaplab
+ // that occasionally causes NPEs to happen in the first call or two
+ // to a given soaplab installation. It also
+ // manifests in the Talisman soaplab clients.
+ return getInputPorts(json);
+ }
+ return inputPorts;
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode json) throws ActivityConfigurationException {
+ Set<ActivityOutputPort> outputPorts = new HashSet<>();
+ try {
+ // Get outputs
+ Map<String, String>[] results = (Map<String, String>[]) Soap
+ .callWebService(json.get("endpoint").textValue(),
+ "getResultSpec");
+ // Iterate over the outputs
+ for (int i = 0; i < results.length; i++) {
+ Map<String, String> output_spec = results[i];
+ String output_name = output_spec.get("name");
+ String output_type = output_spec.get("type").toLowerCase();
+ // Check to see whether the output is either report or
+ // detailed_status, in
+ // which cases we ignore it, this is soaplab metadata rather
+ // than application data.
+ if ((!output_name.equalsIgnoreCase("detailed_status"))) {
+
+ // && (!output_name.equalsIgnoreCase("report"))) {
+ if (output_type.equals("string")) {
+ outputPorts.add(createOutput(output_name, 0, "text/plain"));
+ } else if (output_type.equals("string[]")) {
+ outputPorts.add(createOutput(output_name, 1, "text/plain"));
+ } else if (output_type.equals("byte[]")) {
+ outputPorts.add(createOutput(output_name, 0, "application/octet-stream"));
+ } else if (output_type.equals("byte[][]")) {
+ outputPorts.add(createOutput(output_name, 1, "application/octet-stream"));
+ } else {
+ // Count number of [] to get the arrays right
+ int depth = (output_type.split("\\[\\]", -1).length) -1 ;
+ logger.info("Soaplab output type '" + output_type
+ + "' unknown for output '" + output_name + "' in "
+ + json.get("endpoint").textValue()
+ + ", will add as depth " + depth);
+ outputPorts.add(createOutput(output_name, depth, null));
+ }
+ }
+ }
+
+ } catch (ServiceException se) {
+ throw new ActivityConfigurationException(
+ json.get("endpoint").textValue()
+ + ": Unable to create a new call to connect\n to soaplab, error was : "
+ + se.getMessage());
+ } catch (RemoteException re) {
+ throw new ActivityConfigurationException(
+ ": Unable to call the get spec method for\n endpoint : "
+ + json.get("endpoint").textValue()
+ + "\n Remote exception message "
+ + re.getMessage());
+ } catch (NullPointerException npe) {
+ // If we had a null pointer exception, go around again - this is a
+ // bug somewhere between axis and soaplab
+ // that occasionally causes NPEs to happen in the first call or two
+ // to a given soaplab installation. It also
+ // manifests in the Talisman soaplab clients.
+ return getOutputPorts(json);
+ }
+ return outputPorts;
+ }
+
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+ public ActivityOutputPort createOutput(String portName, int portDepth, String type) {
+ ActivityOutputPort port = edits.createActivityOutputPort(portName, portDepth, portDepth);
+ if (type != null) {
+ MimeType mimeType = new MimeType();
+ mimeType.setText(type);
+ try {
+ edits.getAddAnnotationChainEdit(port, mimeType).doEdit();
+ } catch (EditException e) {
+ logger.debug("Error adding MimeType annotation to port", e);
+ }
+ }
+ return port;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityHealthChecker.java b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityHealthChecker.java
new file mode 100644
index 0000000..69b910e
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityHealthChecker.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
+
+public class SoaplabActivityHealthChecker extends RemoteHealthChecker {
+
+ public boolean canVisit(Object subject) {
+ if (subject == null) {
+ return false;
+ }
+ if (subject instanceof SoaplabActivity) {
+ return true;
+ }
+ if (subject instanceof DisabledActivity) {
+ return (((DisabledActivity) subject).getActivity() instanceof SoaplabActivity);
+ }
+ return false;
+ }
+
+ public VisitReport visit(Object o, List<Object> ancestors) {
+ SoaplabActivityConfigurationBean configuration = null;
+ Activity activity = (Activity) o;
+ if (activity instanceof SoaplabActivity) {
+ configuration = (SoaplabActivityConfigurationBean) activity.getConfiguration();
+ } else if (activity instanceof DisabledActivity) {
+ configuration = (SoaplabActivityConfigurationBean) ((DisabledActivity) activity).getActivityConfiguration();
+ }
+ return contactEndpoint(activity, configuration.getEndpoint());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/taverna-soaplab-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
new file mode 100644
index 0000000..1e52569
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.soaplab.SoaplabActivityHealthChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context-osgi.xml b/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context-osgi.xml
new file mode 100644
index 0000000..434f054
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context-osgi.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="soaplabActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+
+ <service ref="soaplabActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+
+ <reference id="edits" interface="net.sf.taverna.t2.workflowmodel.Edits" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context.xml b/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context.xml
new file mode 100644
index 0000000..8a6eb40
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/resources/META-INF/spring/soaplab-activity-context.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="soaplabActivityHealthChecker" class="net.sf.taverna.t2.activities.soaplab.SoaplabActivityHealthChecker" />
+
+ <bean id="soaplabActivityFactory" class="net.sf.taverna.t2.activities.soaplab.SoaplabActivityFactory">
+ <property name="edits" ref="edits" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/resources/schema.json
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/resources/schema.json b/taverna-soaplab-activity/src/main/resources/schema.json
new file mode 100644
index 0000000..d2a908a
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/resources/schema.json
@@ -0,0 +1,40 @@
+{
+ "$schema": "http://json-schema.org/draft-03/schema#",
+ "id": "http://ns.taverna.org.uk/2010/activity/soaplab.schema.json",
+ "title": "Soaplab consumer activity configuration",
+ "type": "object",
+ "properties": {
+ "@context": {
+ "description": "JSON-LD context for interpreting the configuration as RDF",
+ "required": true,
+ "enum": ["http://ns.taverna.org.uk/2010/activity/soaplab.context.json"]
+ },
+ "endpoint": {
+ "title": "Soaplab Service Endpoint",
+ "description": "The endpoint of the Soaplab service",
+ "type": "string",
+ "required": true
+ }
+ "pollingInterval": {
+ "title": "Polling Interval",
+ "description": "The polling time interval (in milliseconds",
+ "type": "integer",
+ "default": 0,
+ "required": true
+ }
+ "pollingBackoff": {
+ "title": "Polling Backoff",
+ "description": "The polling backoff factor",
+ "type": "number",
+ "default": 1.0,
+ "required": true
+ }
+ "pollingIntervalMax": {
+ "title": "Max Polling Interval",
+ "description": "The maximum polling time interval (in milliseconds)",
+ "type": "integer",
+ "default": 0,
+ "required": true
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBeanTest.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBeanTest.java b/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBeanTest.java
new file mode 100644
index 0000000..3dc9ec3
--- /dev/null
+++ b/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityConfigurationBeanTest.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for SoaplabActivityConfigurationBean.
+ *
+ * @author David Withers
+ */
+public class SoaplabActivityConfigurationBeanTest {
+
+ private SoaplabActivityConfigurationBean bean;
+
+ private String endpoint = "http://www.ebi.ac.uk/soaplab/emboss4/services/utils_misc.embossversion";
+
+ @Before
+ public void setUp() throws Exception {
+ bean = new SoaplabActivityConfigurationBean();
+ }
+
+ @Test
+ public void testGetEndpoint() {
+ assertNull(bean.getEndpoint());
+ }
+
+ @Test
+ public void testSetEndpoint() {
+ bean.setEndpoint(endpoint);
+ assertEquals(endpoint, bean.getEndpoint());
+ bean.setEndpoint(null);
+ assertNull(bean.getEndpoint());
+
+ }
+
+ @Test
+ public void testGetPollingInterval() {
+ assertEquals(0, bean.getPollingInterval());
+ }
+
+ @Test
+ public void testSetPollingInterval() {
+ bean.setPollingInterval(2000);
+ assertEquals(2000, bean.getPollingInterval());
+ }
+
+ @Test
+ public void testGetPollingBackoff() {
+ assertEquals(1.0, bean.getPollingBackoff(), 0);
+ }
+
+ @Test
+ public void testSetPollingBackoff() {
+ bean.setPollingBackoff(1.4);
+ assertEquals(1.4, bean.getPollingBackoff(), 0);
+ }
+
+ @Test
+ public void testGetPollingIntervalMax() {
+ assertEquals(0, bean.getPollingIntervalMax());
+ }
+
+ @Test
+ public void testSetPollingIntervalMax() {
+ bean.setPollingInterval(5000);
+ assertEquals(5000, bean.getPollingInterval());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityTest.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityTest.java b/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityTest.java
new file mode 100644
index 0000000..e0b0dca
--- /dev/null
+++ b/taverna-soaplab-activity/src/test/java/net/sf/taverna/t2/activities/soaplab/SoaplabActivityTest.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Unit tests for SoaplabActivity.
+ *
+ * @author David Withers
+ */
+public class SoaplabActivityTest {
+
+ private SoaplabActivity activity;
+
+ private ObjectNode configurationBean;
+
+ @Ignore("Integration test")
+ @Before
+ public void setUp() throws Exception {
+ activity = new SoaplabActivity();
+ configurationBean = JsonNodeFactory.instance.objectNode();
+ configurationBean.put("endpoint", "http://www.ebi.ac.uk/soaplab/emboss4/services/utils_misc.embossversion");
+ }
+
+ @Ignore("Integration test")
+ @Test
+ public void testExecuteAsynch() throws Exception {
+ Map<String, Object> inputs = new HashMap<String, Object>();
+ // inputs.put("full", "true");
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ expectedOutputs.put("report", String.class);
+ expectedOutputs.put("outfile", String.class);
+
+ activity.configure(configurationBean);
+
+ Map<String, Object> outputs = ActivityInvoker.invokeAsyncActivity(
+ activity, inputs, expectedOutputs);
+ assertTrue(outputs.containsKey("report"));
+ // assertTrue(outputs.get("report") instanceof String);
+ assertTrue(outputs.containsKey("outfile"));
+ assertTrue(outputs.get("outfile") instanceof String);
+ System.out.println(outputs.get("outfile"));
+
+ // test with polling
+ configurationBean.put("pollingInterval", 5);
+ configurationBean.put("PollingIntervalMax", 6);
+ configurationBean.put("PollingBackoff", 1.2);
+ activity.configure(configurationBean);
+
+ outputs = ActivityInvoker.invokeAsyncActivity(activity, inputs,
+ expectedOutputs);
+ assertTrue(outputs.containsKey("report"));
+ assertTrue(outputs.containsKey("outfile"));
+ }
+
+ @Ignore("Integration test")
+ @Test
+ public void testSoaplabActivity() {
+ assertNotNull(new SoaplabActivity());
+ }
+
+ @Ignore("Integration test")
+ @Test
+ public void testConfigureSoaplabActivityConfigurationBean()
+ throws Exception {
+ Set<String> expectedOutputs = new HashSet<String>();
+ expectedOutputs.add("report");
+ expectedOutputs.add("outfile");
+
+ activity.configure(configurationBean);
+ Set<ActivityOutputPort> ports = activity.getOutputPorts();
+ assertEquals(expectedOutputs.size(), ports.size());
+ for (ActivityOutputPort outputPort : ports) {
+ assertTrue("Wrong output : " + outputPort.getName(),
+ expectedOutputs.remove(outputPort.getName()));
+ }
+ }
+
+ @Ignore("Integration test")
+ @Test
+ public void testIsPollingDefined() throws Exception {
+ assertFalse(activity.isPollingDefined());
+ activity.configure(configurationBean);
+ assertFalse(activity.isPollingDefined());
+ configurationBean.put("pollingInterval", 1000);
+ activity.configure(configurationBean);
+ assertTrue(activity.isPollingDefined());
+ }
+
+}
[09/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/QueryTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/QueryTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/QueryTest.java
new file mode 100644
index 0000000..b2b93cc
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/QueryTest.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryTest.java,v $
+ * Revision $Revision: 1.3 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/01 12:11:30 $
+ * by $Author: davidwithers $
+ * Created on 03-May-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class QueryTest extends TestCase {
+ private String attributeName;
+
+ private Attribute attribute;
+
+ private String filterName;
+
+ private String filterValue;
+
+ private Filter filter;
+
+ private Link link;
+
+ private String datasetName;
+
+ private Dataset dataset;
+
+ private String virtualSchemaName;
+
+ private String softwareVersion;
+
+ private String formatter;
+
+ private Query query;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ attributeName = "attribute name";
+ attribute = new Attribute(attributeName);
+
+ filterName = "filter name";
+ filterValue = "filter value";
+ filter = new Filter(filterName, filterValue);
+
+ link = new Link("source", "target", "id");
+
+ datasetName = "dataset name";
+ dataset = new Dataset(datasetName);
+
+ dataset.addAttribute(attribute);
+ dataset.addFilter(filter);
+
+ virtualSchemaName = "default";
+
+ softwareVersion = "software version";
+
+ formatter = "page formatter";
+
+ query = new Query(virtualSchemaName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.Query(String)'
+ */
+ public final void testQueryString() {
+ Query query = new Query(virtualSchemaName);
+ assertEquals("virtualSchemaName should be '" + virtualSchemaName + "'",
+ query.getVirtualSchemaName(), virtualSchemaName);
+ assertEquals("count should be '0'", query.getCount(), 0);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.Query(String, int)'
+ */
+ public final void testQueryStringInt() {
+ Query query = new Query(virtualSchemaName, 1);
+ assertEquals("virtualSchemaName should be '" + virtualSchemaName + "'",
+ query.getVirtualSchemaName(), virtualSchemaName);
+ assertEquals("count should be '1'", query.getCount(), 1);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.Query(Query)'
+ */
+ public final void testQueryQuery() {
+ query.addDataset(dataset);
+ query.addLink(link);
+ query.setCount(1);
+ query.setUniqueRows(1);
+ query.setSoftwareVersion(softwareVersion);
+ query.setFormatter(formatter);
+ Query copy = new Query(query);
+ assertEquals(copy.getDatasets().size(), 1);
+ assertEquals(copy.getAttributes().size(), 1);
+ assertEquals(copy.getFilters().size(), 1);
+ assertEquals(copy.getLinks().size(), 1);
+ assertEquals(copy.getCount(), 1);
+ assertEquals(copy.getUniqueRows(), 1);
+ assertEquals(copy.getSoftwareVersion(), softwareVersion);
+ assertEquals(copy.getFormatter(), formatter);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Query.getVirtualSchemaName()'
+ */
+ public final void testGetVirtualSchemaName() {
+ assertEquals("virtualSchemaName should be '" + virtualSchemaName + "'",
+ query.getVirtualSchemaName(), virtualSchemaName);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Query.setVirtualSchemaName(String)'
+ */
+ public final void testSetVirtualSchemaName() {
+ String newVirtualSchemaName = "new virtual schema name";
+ query.setVirtualSchemaName(newVirtualSchemaName);
+ assertEquals("virtualSchemaName should be '" + newVirtualSchemaName
+ + "'", query.getVirtualSchemaName(), newVirtualSchemaName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getCount()'
+ */
+ public final void testGetCount() {
+ assertEquals("count should be '0'", query.getCount(), 0);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.setCount(int)'
+ */
+ public final void testSetCount() {
+ query.setCount(1);
+ assertEquals("count should be '1'", query.getCount(), 1);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getUniqueRows()'
+ */
+ public final void testGetUniqueRows() {
+ assertEquals("uniqueRows should be '0'", query.getUniqueRows(), 0);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.setUniqueRows(int)'
+ */
+ public final void testSetUniqueRows() {
+ query.setUniqueRows(1);
+ assertEquals("uniqueRows should be '1'", query.getUniqueRows(), 1);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getSoftwareVersion()'
+ */
+ public final void testGetSoftwareVersion() {
+ assertNull("softwareVersion should be null", query.getSoftwareVersion());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.setSoftwareVersion(String)'
+ */
+ public final void testSetSoftwareVersion() {
+ String newSoftwareVersion = "new software version";
+ query.setSoftwareVersion(newSoftwareVersion);
+ assertEquals("softwareVersion should be '" + newSoftwareVersion + "'", query.getSoftwareVersion(), newSoftwareVersion);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getFormatter()'
+ */
+ public final void testGetFormatter() {
+ assertNull("formatter should be null", query.getFormatter());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.setFormatter(String)'
+ */
+ public final void testSetFormatter() {
+ String newFormatter = "new formatter";
+ query.setFormatter(newFormatter);
+ assertEquals("formatter should be '" + newFormatter + "'", query.getFormatter(), newFormatter);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getRequestId()'
+ */
+ public final void testGetRequestId() {
+ assertNull("requestId should be null", query.getRequestId());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.setnewRequestId(String)'
+ */
+ public final void testSetRequestId() {
+ String newRequestId = "new RequestId";
+ query.setRequestId(newRequestId);
+ assertEquals("requestId should be '" + newRequestId + "'", query.getRequestId(), newRequestId);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.addDataset(Dataset)'
+ */
+ public final void testAddDataset() {
+ query.addDataset(dataset);
+ assertEquals(query.getDatasets().size(), 1);
+ assertSame(query.getDatasets().get(0), dataset);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Query.removeDataset(Dataset)'
+ */
+ public final void testRemoveDataset() {
+ query.addDataset(dataset);
+ query.removeDataset(dataset);
+ assertEquals(query.getDatasets().size(), 0);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getDatasets()'
+ */
+ public final void testGetDatasets() {
+ query.addDataset(dataset);
+ assertEquals(query.getDatasets().size(), 1);
+ assertSame(query.getDatasets().get(0), dataset);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getDataset(String)'
+ */
+ public final void testGetDataset() {
+ query.addDataset(dataset);
+ assertSame(query.getDataset(dataset.getName()), dataset);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getAttributes()'
+ */
+ public final void testGetAttributes() {
+ query.addDataset(dataset);
+ assertEquals(query.getAttributes().size(), 1);
+ assertSame(query.getAttributes().get(0), attribute);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Query.getFilters()'
+ */
+ public final void testGetFilters() {
+ query.addDataset(dataset);
+ assertEquals(query.getFilters().size(), 1);
+ assertSame(query.getFilters().get(0), filter);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Query.addQueryListener(QueryListener)'
+ */
+ public final void testAddQueryListener() {
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Query.removeQueryListener(QueryListener)'
+ */
+ public final void testRemoveQueryListener() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/pom.xml b/taverna-biomoby-activity-ui/pom.xml
new file mode 100644
index 0000000..8f92c83
--- /dev/null
+++ b/taverna-biomoby-activity-ui/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.ui-activities</groupId>
+ <artifactId>biomoby-activity-ui</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ <name>Taverna 2 Biomoby Activity UI</name>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-icons-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-palette-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-impl</groupId>
+ <artifactId>activity-palette-impl</artifactId>
+ <version>${t2.ui.impl.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>biomoby-activity</artifactId>
+ <version>${t2.activities.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-impl</groupId>
+ <artifactId>contextual-views-impl</artifactId>
+ <version>${t2.ui.impl.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>contextual-views-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-tools</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+
+ <!-- testing dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+<!-- <dependency>
+ <groupId>net.sf.taverna.t2.ui-impl</groupId>
+ <artifactId>activity-palette-impl</artifactId>
+ <version>${t2.ui.impl.version}</version>
+ <scope>test</scope>
+ </dependency> -->
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository
+ </url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/AddParserActionHelper.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/AddParserActionHelper.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/AddParserActionHelper.java
new file mode 100644
index 0000000..b03b98c
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/AddParserActionHelper.java
@@ -0,0 +1,280 @@
+/*
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JTree;
+import javax.swing.ToolTipManager;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.edits.AddMobyParseDatatypeEdit;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+
+import org.apache.log4j.Logger;
+import org.biomoby.shared.MobyData;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.MobyPrimaryDataSet;
+import org.biomoby.shared.MobyPrimaryDataSimple;
+
+/**
+ * An action to add a parser from within the Workflow editor
+ *
+ * @author Eddie Kawas
+ * @author Stuart Owen - adapted for Taverna 2
+ */
+public class AddParserActionHelper {
+ private static Logger logger = Logger.getLogger(AddParserActionHelper.class);
+
+ private EditManager editManager;
+
+ private final FileManager fileManager;
+
+ public AddParserActionHelper(EditManager editManager, FileManager fileManager) {
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflui.processoractions.AbstractProcessorAction#getComponent(org.embl.ebi.escience.scufl.Processor)
+ */
+ public JComponent getComponent(final BiomobyActivity activity) {
+
+
+ // set up the root node
+ String serviceName = activity.getMobyService().getName();
+ String description = activity.getMobyService().getDescription();
+ MobyServiceTreeNode service = new MobyServiceTreeNode(serviceName,
+ description);
+ DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(service);
+
+ // now add the child nodes containing useful information about the
+ // service
+ DefaultMutableTreeNode output = new DefaultMutableTreeNode("Parse:");
+ rootNode.add(output);
+ // process outputs
+ MobyData[] outputs = activity.getMobyService().getPrimaryOutputs();
+ for (int i = 0; i < outputs.length; i++) {
+ if (outputs[i] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) outputs[i];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ sb.append(namespaces[j].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append(" ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ mobyObjectTreeNode.setNamespaces(simple.getNamespaces());
+ output.insert(new DefaultMutableTreeNode(mobyObjectTreeNode),
+ output.getChildCount());
+ } else {
+ // we have a collection
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) outputs[i];
+ DefaultMutableTreeNode collectionNode = new DefaultMutableTreeNode(
+ "Collection('" + collection.getName() + "')");
+ output.insert(collectionNode, output.getChildCount());
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int j = 0; j < simples.length; j++) {
+ MobyPrimaryDataSimple simple = simples[j];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int k = 0; k < namespaces.length; k++) {
+ sb.append(namespaces[k].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append("ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ mobyObjectTreeNode.setNamespaces(simple.getNamespaces());
+ collectionNode
+ .insert(new DefaultMutableTreeNode(
+ mobyObjectTreeNode), collectionNode
+ .getChildCount());
+ }
+
+ }
+ }
+ if (outputs.length == 0) {
+ output.add(new DefaultMutableTreeNode(" None "));
+ }
+
+ // finally return a tree describing the object
+ final JTree tree = new JTree(rootNode);
+ tree.setCellRenderer(new BioMobyServiceTreeCustomRenderer());
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ tree.addMouseListener(new MouseListener() {
+ public void mouseClicked(MouseEvent me) {
+ }
+
+ public void mousePressed(MouseEvent me) {
+ mouseReleased(me);
+ }
+
+ public void mouseReleased(MouseEvent me) {
+ if (me.isPopupTrigger()) // right click, show popup menu
+ {
+ TreePath path = tree.getPathForLocation(me.getX(), me
+ .getY());
+ if (path == null)
+ return;
+ if (path.getPathCount() >= 3) {
+ if (path.getParentPath().toString().indexOf("Parse:") >= 0
+ && path.getLastPathComponent().toString()
+ .indexOf(" None ") == -1) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ if (node == null)
+ return;
+ final String selectedObject = node.toString();
+ if (!selectedObject.equals(path
+ .getLastPathComponent().toString()))
+ return;
+
+ logger.debug("TreePath " + path.toString());
+ if (
+ // path has a collection in it
+ (path.getPathCount() == 4
+ && path.getParentPath()
+ .getLastPathComponent().toString()
+ .startsWith("Collection(") && (path
+ .getParentPath().toString())
+ .indexOf("Parse:") > 0)
+ // or path is just a simple
+ || (path.toString().indexOf("Collection(") < 0)) {
+
+ final JPopupMenu menu = new JPopupMenu();
+
+ final String potentialCollectionString = path
+ .getParentPath().getLastPathComponent()
+ .toString();
+ final boolean isCollection = potentialCollectionString
+ .indexOf("Collection('") >= 0;
+ JMenuItem item3 = new JMenuItem(
+ "Add parser for " + selectedObject
+ + " to the workflow");
+ item3
+ .setIcon(getIcon("/Cut24.gif"));
+ item3.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent ae) {
+ // you would like to search for
+ // selectedObject
+ try {
+ try {
+ Dataflow currentDataflow = fileManager.getCurrentDataflow();
+ Edit<?> edit = new AddMobyParseDatatypeEdit(
+ currentDataflow, activity,
+ selectedObject,isCollection, potentialCollectionString, editManager.getEdits());
+ editManager.doDataflowEdit(
+ currentDataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+
+ }
+ });
+
+ menu.add(new JSeparator());
+ menu.add(new JLabel("Parse Moby Data ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item3);
+ menu.show(me.getComponent(), me.getX(), me
+ .getY());
+ } else {
+ logger
+ .debug("unexpected situation occured; '"
+ + selectedObject
+ + "' was the object selected and the path is: "
+ + path.toString());
+ }
+ }
+ }
+ }
+ }
+
+ public void mouseEntered(MouseEvent me) {
+ }
+
+ public void mouseExited(MouseEvent me) {
+ }
+ });
+
+ tree.getSelectionModel().setSelectionMode(
+ TreeSelectionModel.SINGLE_TREE_SELECTION);
+ JScrollPane jsp = new JScrollPane(tree);
+ JPanel thePanel = new JPanel(new BorderLayout());
+ thePanel.add(jsp, BorderLayout.CENTER);
+ return thePanel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflui.processoractions.ProcessorActionSPI#getDescription()
+ */
+ public String getDescription() {
+ return "Add BioMOBY Parser ...";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflui.processoractions.ProcessorActionSPI#getIcon()
+ */
+ public ImageIcon getIcon() {
+ return MobyPanel.getIcon("/Cut24.gif");
+ }
+
+ /**
+ * returns the frame size as a dimension for the content pane housing
+ * this action
+ */
+ public Dimension getFrameSize() {
+ return new Dimension(450, 450);
+ }
+
+ /**
+ * Return an Icon to represent this action
+ *
+ * @param loc
+ * the location of the image to use as an icon
+ */
+ private ImageIcon getIcon(String loc) {
+ return MobyPanel.getIcon(loc);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyObjectTreeCustomRenderer.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyObjectTreeCustomRenderer.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyObjectTreeCustomRenderer.java
new file mode 100644
index 0000000..46b4d5a
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyObjectTreeCustomRenderer.java
@@ -0,0 +1,97 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.JComponent;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+public class BioMobyObjectTreeCustomRenderer extends DefaultTreeCellRenderer {
+
+ private static final long serialVersionUID = 1L;
+
+ private Color leafForeground = Color.blue;
+
+ private Color rootColor = Color.black;
+
+ @SuppressWarnings("unused")
+ private Color feedsIntoColor = Color.gray;
+
+ @SuppressWarnings("unused")
+ private Color producedColor = Color.lightGray;
+
+ @SuppressWarnings("unused")
+ private Color authorityColor = Color.orange;
+
+ private Color serviceColor = Color.magenta;
+
+ private Color objectColor = Color.green;
+
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean selected, boolean expanded, boolean leaf, int row,
+ boolean hasFocus) {
+ // Allow the original renderer to set up the label
+ Component c = super.getTreeCellRendererComponent(tree, value, selected,
+ expanded, leaf, row, hasFocus);
+
+ if (value instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ if (node.getUserObject() instanceof MobyServiceTreeNode) {
+ // service node
+ c.setForeground(serviceColor);
+ ((JComponent) c).setToolTipText(((MobyServiceTreeNode) node
+ .getUserObject()).getDescription());
+ setIcon(MobyPanel.getIcon("/service.png"));
+ } else if (node.getUserObject() instanceof MobyObjectTreeNode) {
+ // object node
+ c.setForeground(objectColor);
+ ((JComponent) c).setToolTipText(((MobyObjectTreeNode) node
+ .getUserObject()).getDescription());
+ } else if (node.isRoot()) {
+ // root node
+ setIcon(MobyPanel.getIcon("/moby.png"));
+ ((JComponent) c).setToolTipText(" Description of "
+ + node.getUserObject());
+ c.setForeground(rootColor);
+ } else if (node.getUserObject() instanceof String) {
+ // check for feeds into and produced by nodes
+ String string = (String) node.getUserObject();
+ if (string.equalsIgnoreCase("feeds into")) {
+ setIcon(MobyPanel.getIcon("/input.png"));
+ ((JComponent) c).setToolTipText(null);
+ } else if (string.equalsIgnoreCase("produced by")) {
+ setIcon(MobyPanel.getIcon("/output.png"));
+ ((JComponent) c).setToolTipText(null);
+ } else if (string.equalsIgnoreCase("produces")) {
+ ((JComponent) c).setToolTipText(null);
+ } else {
+
+ ((JComponent) c).setToolTipText(null);
+
+ if (!leaf) {
+ if (string.startsWith("Collection('")) {
+ setIcon(MobyPanel.getIcon("/collection.png"));
+ } else {
+ setIcon(MobyPanel.getIcon("/authority.png"));
+ }
+ }
+ }
+
+ } else {
+ ((JComponent) c).setToolTipText("nothing node");
+ }
+ }
+ if (selected)
+ c.setBackground(Color.lightGray);
+ if (leaf)
+ c.setForeground(this.leafForeground);
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyServiceTreeCustomRenderer.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyServiceTreeCustomRenderer.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyServiceTreeCustomRenderer.java
new file mode 100644
index 0000000..ecce3ca
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BioMobyServiceTreeCustomRenderer.java
@@ -0,0 +1,86 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.JComponent;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+public class BioMobyServiceTreeCustomRenderer extends DefaultTreeCellRenderer {
+
+ private static final long serialVersionUID = 1L;
+
+ private Color leafForeground = Color.blue;
+
+ @SuppressWarnings("unused")
+ private Color rootColor = Color.black;
+
+ @SuppressWarnings("unused")
+ private Color feedsIntoColor = Color.gray;
+
+ @SuppressWarnings("unused")
+ private Color producedColor = Color.lightGray;
+
+ @SuppressWarnings("unused")
+ private Color authorityColor = Color.orange;
+
+ private Color serviceColor = Color.magenta;
+
+ private Color objectColor = Color.green;
+
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean selected, boolean expanded, boolean leaf, int row,
+ boolean hasFocus) {
+ // Allow the original renderer to set up the label
+ Component c = super.getTreeCellRendererComponent(tree, value, selected,
+ expanded, leaf, row, hasFocus);
+
+ if (value instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ if (node.getUserObject() instanceof MobyServiceTreeNode) {
+ // service node
+ c.setForeground(serviceColor);
+ ((JComponent) c).setToolTipText(((MobyServiceTreeNode) node
+ .getUserObject()).getDescription());
+ setIcon(MobyPanel.getIcon("/service.png"));
+ } else if (node.getUserObject() instanceof MobyObjectTreeNode) {
+ // object node
+ c.setForeground(objectColor);
+ ((JComponent) c).setToolTipText(((MobyObjectTreeNode) node
+ .getUserObject()).getDescription());
+ } else if (node.getUserObject() instanceof String) {
+ // check for feeds into and produced by nodes
+ String string = (String) node.getUserObject();
+ if (string.equalsIgnoreCase("inputs")) {
+ setIcon(MobyPanel.getIcon("/input.png"));
+ ((JComponent) c).setToolTipText(null);
+ } else if (string.equalsIgnoreCase("outputs")) {
+ setIcon(MobyPanel.getIcon("/output.png"));
+ ((JComponent) c).setToolTipText(null);
+ } else {
+
+ ((JComponent) c).setToolTipText(null);
+
+ if (!leaf) {
+ if (string.startsWith("Collection('")) {
+ setIcon(MobyPanel.getIcon("/collection.png"));
+ }
+ }
+ }
+
+ } else {
+ ((JComponent) c).setToolTipText("nothing node");
+ }
+ }
+ if (leaf)
+ c.setForeground(this.leafForeground);
+ return c;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActionHelper.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActionHelper.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActionHelper.java
new file mode 100644
index 0000000..9579627
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActionHelper.java
@@ -0,0 +1,852 @@
+/*
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import javax.swing.ImageIcon;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JProgressBar;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JTree;
+import javax.swing.ToolTipManager;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.edits.AddBiomobyCollectionDataTypeEdit;
+import net.sf.taverna.t2.activities.biomoby.edits.AddBiomobyDataTypeEdit;
+import net.sf.taverna.t2.activities.biomoby.edits.AddMobyParseDatatypeEdit;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyData;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.MobyPrimaryDataSet;
+import org.biomoby.shared.MobyPrimaryDataSimple;
+import org.biomoby.shared.NoSuccessException;
+
+
+/**
+ *
+ * @author Eddie An action that for BioMobyProcessors
+ * @auther Stuart Owen - helped port to T2 - but with the minimum code changes possible!
+ */
+public class BiomobyActionHelper {
+
+ private static Logger logger = Logger
+ .getLogger(BiomobyActionHelper.class);
+
+ JProgressBar progressBar = new JProgressBar();
+
+ private EditManager editManager;
+
+ private final FileManager fileManager;
+
+ public BiomobyActionHelper(EditManager editManager, FileManager fileManager) {
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.embl.ebi.escience.scuflui.processoractions.AbstractProcessorAction
+ * #getComponent(org.embl.ebi.escience.scufl.Processor)
+ */
+
+ public JComponent getComponent(final BiomobyActivity activity) {
+ // variables i need
+
+ final String endpoint = activity.getConfiguration().getMobyEndpoint();
+ // set up the root node
+ String serviceName = activity.getMobyService().getName();
+ String description = activity.getMobyService().getDescription();
+
+ MobyServiceTreeNode service = new MobyServiceTreeNode(serviceName,
+ description);
+ DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(service);
+
+ // now add the child nodes containing useful information about the
+ // service
+ DefaultMutableTreeNode input = new DefaultMutableTreeNode("Inputs");
+ DefaultMutableTreeNode output = new DefaultMutableTreeNode("Outputs");
+ rootNode.add(input);
+ rootNode.add(output);
+
+ // process inputs
+ MobyData[] inputs = activity.getMobyService().getPrimaryInputs();
+ for (int i = 0; i < inputs.length; i++) {
+ if (inputs[i] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) inputs[i];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ sb.append(namespaces[j].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append(" ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ input.insert(new DefaultMutableTreeNode(mobyObjectTreeNode),
+ input.getChildCount());
+ } else {
+ // we have a collection
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) inputs[i];
+ DefaultMutableTreeNode collectionNode = new DefaultMutableTreeNode(
+ "Collection('" + collection.getName() + "')");
+ input.insert(collectionNode, input.getChildCount());
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int j = 0; j < simples.length; j++) {
+ MobyPrimaryDataSimple simple = simples[j];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int k = 0; k < namespaces.length; k++) {
+ sb.append(namespaces[k].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append(" ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ collectionNode
+ .insert(new DefaultMutableTreeNode(
+ mobyObjectTreeNode), collectionNode
+ .getChildCount());
+ }
+
+ }
+ }
+ if (inputs.length == 0) {
+ input.add(new DefaultMutableTreeNode(" None "));
+ }
+
+ // process outputs
+ MobyData[] outputs = activity.getMobyService().getPrimaryOutputs();
+ for (int i = 0; i < outputs.length; i++) {
+ if (outputs[i] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) outputs[i];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ sb.append(namespaces[j].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append(" ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ mobyObjectTreeNode.setNamespaces(simple.getNamespaces());
+ output.insert(new DefaultMutableTreeNode(mobyObjectTreeNode),
+ output.getChildCount());
+ } else {
+ // we have a collection
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) outputs[i];
+ DefaultMutableTreeNode collectionNode = new DefaultMutableTreeNode(
+ "Collection('" + collection.getName() + "')");
+ output.insert(collectionNode, output.getChildCount());
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int j = 0; j < simples.length; j++) {
+ MobyPrimaryDataSimple simple = simples[j];
+ StringBuffer sb = new StringBuffer(
+ "Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int k = 0; k < namespaces.length; k++) {
+ sb.append(namespaces[k].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append("ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(
+ simple.getDataType().getName() + "('"
+ + simple.getName() + "')", sb.toString());
+ mobyObjectTreeNode.setNamespaces(simple.getNamespaces());
+ collectionNode
+ .insert(new DefaultMutableTreeNode(
+ mobyObjectTreeNode), collectionNode
+ .getChildCount());
+ }
+
+ }
+ }
+ if (outputs.length == 0) {
+ output.add(new DefaultMutableTreeNode(" None "));
+ }
+
+ // finally return a tree describing the object
+ final JTree tree = new JTree(rootNode);
+ tree.setCellRenderer(new BioMobyServiceTreeCustomRenderer());
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ tree.addMouseListener(new MouseListener() {
+ public void mouseClicked(MouseEvent me) {
+ }
+
+ public void mousePressed(MouseEvent me) {
+ mouseReleased(me);
+ }
+
+ public void mouseReleased(MouseEvent me) {
+ if (me.isPopupTrigger()) // right click, show popup menu
+ {
+ TreePath path = tree.getPathForLocation(me.getX(), me
+ .getY());
+ if (path == null)
+ return;
+ if (path.getPathCount() >= 3) {
+ if (path.getPathCount() == 4
+ && path.getParentPath().getLastPathComponent()
+ .toString().startsWith("Collection(")
+ && (path.getParentPath().toString())
+ .indexOf("Inputs") > 0) {
+ // we have a collection input
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ final String selectedObject = node.toString();
+ // ensure that the last selected item is an object!
+ if (!selectedObject.equals(path
+ .getLastPathComponent().toString()))
+ return;
+ String collectionName = "";
+ if (path.getParentPath().getLastPathComponent()
+ .toString().indexOf("('") > 0
+ && path.getParentPath()
+ .getLastPathComponent().toString()
+ .indexOf("')") > 0) {
+ collectionName = path.getParentPath()
+ .getLastPathComponent().toString()
+ .substring(
+ path.getParentPath()
+ .getLastPathComponent()
+ .toString().indexOf(
+ "('") + 2,
+ path.getParentPath()
+ .getLastPathComponent()
+ .toString().indexOf(
+ "')"));
+ }
+ final String theCollectionName = collectionName;
+ final JPopupMenu menu = new JPopupMenu();
+ // Create and add a menu item for adding to the item
+ // to the workflow
+ JMenuItem item = new JMenuItem("Add Datatype - "
+ + selectedObject + " to the workflow?");
+ item
+ .setIcon(MobyPanel.getIcon("/Add24.gif"));
+ item.addActionListener(new ActionListener() {
+ // private boolean added = false;
+
+ public void actionPerformed(ActionEvent ae) {
+
+ try {
+ Dataflow currentDataflow = fileManager.getCurrentDataflow();
+ Edit<?> edit = new AddBiomobyCollectionDataTypeEdit(
+ currentDataflow, activity,
+ selectedObject,
+ theCollectionName, editManager.getEdits());
+ editManager.doDataflowEdit(
+ currentDataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+ }
+ });
+ // Create and add a menu item for service details
+ JMenuItem details = new JMenuItem("Find out about "
+ + selectedObject);
+ details
+ .setIcon(MobyPanel.getIcon("/Information24.gif"));
+ details.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+
+ // TODO Create a frame
+ Frame frame = MobyPanel.CreateFrame("A BioMoby Object Description");
+ JPanel panel = new MobyPanel(
+ selectedObject,
+ "A BioMoby Object Description", "");
+
+ frame.add(panel);
+ frame.setSize(getFrameSize());
+ frame.pack();
+ frame.setVisible(true);
+ }
+ });
+ // add the components to the menu
+ menu.add(new JLabel("Add to workflow ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item);
+ menu.add(new JSeparator());
+ menu.add(new JLabel("Datatype Details ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(details);
+ // show the window
+ menu.show(me.getComponent(), me.getX(), me.getY());
+ } else if (path.getPathCount() == 3
+ && path.getParentPath().getLastPathComponent()
+ .toString().startsWith("Inputs")
+ && !path.getLastPathComponent().toString()
+ .startsWith("Collection(")
+ && !path.getLastPathComponent().toString()
+ .equals(" None ")) {
+ // we have a simple input
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ if (node == null)
+ return;
+ final String selectedObject = node.toString();
+ // ensure that the last selected item is an object!
+ if (!selectedObject.equals(path
+ .getLastPathComponent().toString()))
+ return;
+
+ final JPopupMenu menu = new JPopupMenu();
+ // Create and add a menu item for adding to the item
+ // to the workflow
+ JMenuItem item = new JMenuItem("Add Datatype - "
+ + selectedObject + " to the workflow?");
+ item
+ .setIcon(MobyPanel.getIcon("/Add24.gif"));
+ item.addActionListener(new ActionListener() {
+ // private boolean added = false;
+
+ public void actionPerformed(ActionEvent ae) {
+
+ try {
+ Dataflow currentDataflow = fileManager.getCurrentDataflow();
+ Edit<?> edit = new AddBiomobyDataTypeEdit(
+ currentDataflow, activity,
+ selectedObject, editManager.getEdits());
+ editManager.doDataflowEdit(
+ currentDataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("Could not perform action", e);
+ }
+ }
+ });
+
+ // Create and add a menu item for service details
+ JMenuItem details = new JMenuItem(
+ "Find out about 1 " + selectedObject);
+ details
+ .setIcon(MobyPanel.getIcon("/Information24.gif"));
+ details.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ // TODO Create a frame
+ Frame frame = MobyPanel.CreateFrame("A BioMoby Object Description");
+ JPanel panel = new MobyPanel(
+ // TODO create a valid description
+ selectedObject,
+ "A BioMoby Object Description",
+ createDataDescription(
+ selectedObject.split("\\(")[0],
+ activity.getConfiguration()
+ .getMobyEndpoint()));
+ frame.add(panel);
+ frame.setSize(getFrameSize());
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ private String createDataDescription(
+ String dataName, String mobyEndpoint) {
+ MobyDataType data;
+ try {
+ Central central = new CentralImpl(
+ mobyEndpoint);
+ data = central.getDataType(dataName);
+
+ } catch (MobyException e) {
+ return "Couldn't retrieve a description on the BioMoby service '"
+ + dataName + "'";
+ } catch (NoSuccessException e) {
+ return "Couldn't retrieve a description on the BioMoby service '"
+ + dataName + "'";
+ }
+ return data.toString();
+ }
+ });
+ // add the components to the menu
+ menu.add(new JLabel("Add to workflow ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item);
+ menu.add(new JSeparator());
+ menu.add(new JLabel("Datatype Details ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(details);
+ // show the window
+ menu.show(me.getComponent(), me.getX(), me.getY());
+
+ } else if (path.getParentPath().toString().indexOf(
+ "Outputs") >= 0
+ && path.getLastPathComponent().toString()
+ .indexOf(" None ") == -1) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ if (node == null)
+ return;
+ final String selectedObject = node.toString();
+ if (!selectedObject.equals(path
+ .getLastPathComponent().toString()))
+ return;
+
+ if ((path.getPathCount() == 4
+ && path.getParentPath()
+ .getLastPathComponent().toString()
+ .startsWith("Collection(") && (path
+ .getParentPath().toString())
+ .indexOf("Outputs") > 0)
+ || (path.toString().indexOf("Collection(") < 0)) {
+ final JPopupMenu menu = new JPopupMenu();
+ JMenuItem item = new JMenuItem(
+ "Find Services that Consume "
+ + selectedObject
+ + " - brief search");
+ item
+ .setIcon(MobyPanel.getIcon("/Information24.gif"));
+ final String potentialCollectionString = path
+ .getParentPath().getLastPathComponent()
+ .toString();
+ final boolean isCollection = potentialCollectionString
+ .indexOf("Collection('") >= 0;
+ final Object selectedMobyObjectTreeNodeHolder = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ item.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent ae) {
+ // you would like to search for
+ // selectedObject
+ new Thread("Finding biomoby services") {
+ public void run() {
+ try {
+ // FIXME: ignored for now -
+ // Stuart
+ String name = selectedObject;
+ if (name.indexOf("(") > 0)
+ name = name
+ .substring(
+ 0,
+ name
+ .indexOf("("));
+ String articlename = "";
+ if (isCollection) {
+ articlename = potentialCollectionString
+ .substring(
+ potentialCollectionString
+ .indexOf("('") + 2,
+ potentialCollectionString
+ .lastIndexOf("'"));
+ } else {
+ articlename = selectedObject
+ .substring(
+ selectedObject
+ .indexOf("'") + 1,
+ selectedObject
+ .lastIndexOf("'"));
+ }
+
+ BiomobyObjectActivity boAct = new BiomobyObjectActivity();
+ BiomobyObjectActivityConfigurationBean bean = new BiomobyObjectActivityConfigurationBean();
+ MobyDataType dataType = new MobyDataType(
+ name);
+ bean
+ .setAuthorityName(dataType
+ .getAuthority());
+ bean
+ .setServiceName(dataType
+ .getName());
+ bean
+ .setMobyEndpoint(endpoint);
+ boAct.configure(bean);
+
+ OutputPort theServiceport = null;
+
+ try {
+ if (isCollection)
+ theServiceport = Tools
+ .getActivityOutputPort(
+ activity,
+ name
+ + "(Collection - '"
+ + (articlename
+ .equals("") ? "MobyCollection"
+ : articlename)
+ + "' As Simples)");
+
+ else
+ theServiceport = Tools
+ .getActivityOutputPort(
+ activity,
+ name
+ + "("
+ + articlename
+ + ")");
+ } catch (Exception except) {
+ }
+ BiomobyObjectActionHelper boa = null;
+
+ if (theServiceport == null) {
+ boa = new BiomobyObjectActionHelper(
+ false, editManager, fileManager);
+ } else {
+ boa = new BiomobyObjectActionHelper(
+ theServiceport,
+ false, editManager, fileManager);
+ }
+
+ if (selectedMobyObjectTreeNodeHolder instanceof DefaultMutableTreeNode
+ && ((DefaultMutableTreeNode) selectedMobyObjectTreeNodeHolder)
+ .getUserObject() instanceof MobyObjectTreeNode) {
+ DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) selectedMobyObjectTreeNodeHolder;
+ MobyObjectTreeNode motn = (MobyObjectTreeNode) dmtn
+ .getUserObject();
+ boa
+ .setNamespaces(motn
+ .getNamespaces());
+ }
+ PopupThread popupthread = new PopupThread(
+ boAct, boa);
+ progressBar
+ .setStringPainted(true);
+ progressBar
+ .setVisible(true);
+ popupthread.start();
+
+ while (popupthread
+ .isAlive()) {
+ Thread.sleep(4000);
+ }
+
+ progressBar
+ .setVisible(false);
+ Component c = popupthread
+ .getComponent();
+ Dimension loc = getFrameLocation();
+ Dimension size = getFrameSize();
+ JPanel frame = new SimpleActionFrame(
+ c,
+ "Moby Object Details");
+ createFrame(
+ frame,
+ (int) loc
+ .getWidth(),
+ (int) loc
+ .getHeight(),
+ (int) size
+ .getWidth(),
+ (int) size
+ .getHeight());
+ } catch (Exception e) {
+ }
+ }
+ }.start();
+
+ }
+ });
+
+ JMenuItem item2 = new JMenuItem(
+ "Find Services that Consume "
+ + selectedObject
+ + " - semantic search");
+ item2
+ .setIcon(MobyPanel.getIcon("/Search24.gif"));
+ item2.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ // you would like to search for
+ // selectedObject
+ new Thread("Finding BioMoby services") {
+
+ public void run() {
+ try {
+ String name = selectedObject;
+ if (name.indexOf("(") > 0)
+ name = name
+ .substring(
+ 0,
+ name
+ .indexOf("("));
+ String articlename = "";
+ if (isCollection) {
+ articlename = potentialCollectionString
+ .substring(
+ potentialCollectionString
+ .indexOf("('") + 2,
+ potentialCollectionString
+ .lastIndexOf("'"));
+ } else {
+ articlename = selectedObject
+ .substring(
+ selectedObject
+ .indexOf("'") + 1,
+ selectedObject
+ .lastIndexOf("'"));
+ }
+ BiomobyObjectActivity boAct = new BiomobyObjectActivity();
+ BiomobyObjectActivityConfigurationBean bean = new BiomobyObjectActivityConfigurationBean();
+ MobyDataType dataType = new MobyDataType(
+ name);
+ bean
+ .setAuthorityName(dataType
+ .getAuthority());
+ bean
+ .setServiceName(dataType
+ .getName());
+ bean
+ .setMobyEndpoint(endpoint);
+ boAct.configure(bean);
+
+ OutputPort theServiceport = null;
+
+ try {
+
+ if (isCollection)
+ theServiceport = Tools
+ .getActivityOutputPort(
+ activity,
+ name
+ + "(Collection - '"
+ + (articlename
+ .equals("") ? "MobyCollection"
+ : articlename)
+ + "' As Simples)");
+
+ else
+ theServiceport = Tools
+ .getActivityOutputPort(
+ activity,
+ name
+ + "("
+ + articlename
+ + ")");
+ } catch (Exception except) {
+ }
+ BiomobyObjectActionHelper boa = null;
+
+ if (theServiceport == null)
+ boa = new BiomobyObjectActionHelper(
+ true, editManager, fileManager);
+ else
+ boa = new BiomobyObjectActionHelper(
+ theServiceport,
+ true, editManager, fileManager);
+ if (selectedMobyObjectTreeNodeHolder instanceof DefaultMutableTreeNode
+ && ((DefaultMutableTreeNode) selectedMobyObjectTreeNodeHolder)
+ .getUserObject() instanceof MobyObjectTreeNode) {
+ DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) selectedMobyObjectTreeNodeHolder;
+ MobyObjectTreeNode motn = (MobyObjectTreeNode) dmtn
+ .getUserObject();
+ boa
+ .setNamespaces(motn
+ .getNamespaces());
+ }
+
+ PopupThread popupthread = new PopupThread(
+ boAct, boa);
+ progressBar
+ .setStringPainted(true);
+ progressBar
+ .setVisible(true);
+ popupthread.start();
+
+ while (popupthread
+ .isAlive()) {
+ Thread.sleep(4000);
+ }
+
+ progressBar
+ .setVisible(false);
+ Component c = popupthread
+ .getComponent();
+ Dimension loc = getFrameLocation();
+ Dimension size = getFrameSize();
+ JPanel frame = new SimpleActionFrame(
+ c,
+ "Moby Object Details");
+ createFrame(
+ frame,
+ (int) loc
+ .getWidth(),
+ (int) loc
+ .getHeight(),
+ (int) size
+ .getWidth(),
+ (int) size
+ .getHeight());
+ } catch (Exception e) {
+ }
+ }
+ }.start();
+ }
+ });
+
+ // string may be needed to extract the
+ // collection article name
+ // final String potentialCollectionString =
+ // path.getParentPath()
+ // .getLastPathComponent().toString();
+ // final boolean isCollection =
+ // potentialCollectionString
+ // .indexOf("Collection('") >= 0;
+
+ JMenuItem item3 = new JMenuItem(
+ "Add parser for " + selectedObject
+ + " to the workflow");
+ item3
+ .setIcon(MobyPanel.getIcon("/Cut24.gif"));
+ item3.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent ae) {
+
+ try {
+ Dataflow currentDataflow = fileManager.getCurrentDataflow();
+ Edit<?> edit = new AddMobyParseDatatypeEdit(
+ currentDataflow, activity,
+ selectedObject,isCollection, potentialCollectionString, editManager.getEdits());
+ editManager.doDataflowEdit(
+ currentDataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("Could not perform action", e);
+ }
+
+ }
+ });
+
+ menu.add(new JLabel(
+ "Moby Service Discovery ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item);
+ menu.add(new JSeparator());
+ menu.add(item2);
+ menu.add(new JLabel("Parse Moby Data ... ",
+ JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item3);
+
+ menu.show(me.getComponent(), me.getX(), me
+ .getY());
+ }
+ }
+ }
+ }
+ }
+
+ public void mouseEntered(MouseEvent me) {
+ }
+
+ public void mouseExited(MouseEvent me) {
+ }
+ });
+
+ tree.getSelectionModel().setSelectionMode(
+ TreeSelectionModel.SINGLE_TREE_SELECTION);
+ JScrollPane jsp = new JScrollPane(tree);
+ JPanel thePanel = new JPanel(new BorderLayout());
+ thePanel.add(jsp, BorderLayout.CENTER);
+ progressBar = new JProgressBar();
+ progressBar.setValue(0);
+ progressBar.setString("Finding Services ... ");
+ progressBar.setStringPainted(true);
+ progressBar.setIndeterminate(true);
+ progressBar.setVisible(false);
+ thePanel.add(progressBar, BorderLayout.PAGE_END);
+ return thePanel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.embl.ebi.escience.scuflui.processoractions.ProcessorActionSPI#
+ * getDescription()
+ */
+ public String getDescription() {
+ return "Moby Service Details";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.embl.ebi.escience.scuflui.processoractions.ProcessorActionSPI#getIcon
+ * ()
+ */
+ public ImageIcon getIcon() {
+ return MobyPanel.getIcon("/moby_small.gif");
+ }
+
+ /**
+ * returns the frame size as a dimension for the content pane housing this
+ * action
+ */
+ public Dimension getFrameSize() {
+ return new Dimension(450, 450);
+ }
+
+ /**
+ * Return an Icon to represent this action
+ *
+ * @param loc
+ * the location of the image to use as an icon
+ */
+ public ImageIcon getIcon(String loc) {
+ return MobyPanel.getIcon(loc);
+ }
+
+ /**
+ * Where should the frame open?
+ */
+ public Dimension getFrameLocation() {
+ return new Dimension(100, 100);
+ }
+
+ public void createFrame(JPanel targetComponent,
+ int posX, int posY, int sizeX, int sizeY) {
+ final JPanel component = targetComponent;
+ JFrame newFrame = new JFrame(component.getName());
+ newFrame.getContentPane().setLayout(new BorderLayout());
+ newFrame.getContentPane().add(
+ new JScrollPane((JComponent) targetComponent),
+ BorderLayout.CENTER);
+ newFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ newFrame.setSize(sizeX, sizeY);
+ newFrame.setLocation(posX, posY);
+ newFrame.setVisible(true);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActivityConfigurationAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActivityConfigurationAction.java
new file mode 100644
index 0000000..f74c76a
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyActivityConfigurationAction.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.view.BiomobyConfigView;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
+
+import org.apache.log4j.Logger;
+
+@SuppressWarnings("serial")
+public class BiomobyActivityConfigurationAction extends
+ ActivityConfigurationAction<BiomobyActivity, BiomobyActivityConfigurationBean> {
+
+ private final Frame owner;
+ private static Logger logger = Logger.getLogger(BiomobyActivityConfigurationAction.class);
+ private final EditManager editManager;
+ private final FileManager fileManager;
+
+ public BiomobyActivityConfigurationAction(BiomobyActivity activity, Frame owner,
+ EditManager editManager, FileManager fileManager,
+ ActivityIconManager activityIconManager) {
+ super(activity, activityIconManager);
+ this.owner = owner;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ public void actionPerformed(ActionEvent arg0) {
+ ActivityConfigurationDialog<BiomobyActivity, BiomobyActivityConfigurationBean> currentDialog = ActivityConfigurationAction
+ .getDialog(getActivity());
+ if (currentDialog != null) {
+ currentDialog.toFront();
+ return;
+ }
+
+ final BiomobyConfigView biomobyConfigView = new BiomobyConfigView(
+ (BiomobyActivity) getActivity());
+ final ActivityConfigurationDialog<BiomobyActivity, BiomobyActivityConfigurationBean> dialog = new ActivityConfigurationDialog<BiomobyActivity, BiomobyActivityConfigurationBean>(
+ getActivity(), biomobyConfigView, editManager, fileManager);
+
+ ActivityConfigurationAction.setDialog(getActivity(), dialog, fileManager);
+ }
+
+ public boolean isEnabled() {
+ BiomobyActivity activity = (BiomobyActivity) getActivity();
+ return (activity.getMobyService() != null && activity.containsSecondaries());
+ }
+
+}
[10/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_3utr.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_3utr.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_3utr.gif
new file mode 100644
index 0000000..3e0e2ac
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_3utr.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_5utr.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_5utr.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_5utr.gif
new file mode 100644
index 0000000..2ebe5a5
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_5utr.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_cdna.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_cdna.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_cdna.gif
new file mode 100644
index 0000000..ad08e22
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_cdna.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding.gif
new file mode 100644
index 0000000..6944b2b
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_gene_flank.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_gene_flank.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_gene_flank.gif
new file mode 100644
index 0000000..8dbc528
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_gene_flank.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_transcript_flank.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_transcript_flank.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_transcript_flank.gif
new file mode 100644
index 0000000..093e316
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_coding_transcript_flank.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon.gif
new file mode 100644
index 0000000..9bb1258
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon_intron.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon_intron.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon_intron.gif
new file mode 100644
index 0000000..ba3b184
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_exon_intron.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_flank.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_flank.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_flank.gif
new file mode 100644
index 0000000..d9e0520
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_gene_flank.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_peptide.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_peptide.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_peptide.gif
new file mode 100644
index 0000000..6944b2b
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_peptide.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon.gif
new file mode 100644
index 0000000..6ac00a4
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon_intron.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon_intron.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon_intron.gif
new file mode 100644
index 0000000..aa4e783
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_exon_intron.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_flank.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_flank.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_flank.gif
new file mode 100644
index 0000000..2aece28
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic_transcript_flank.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartDatasetTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartDatasetTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartDatasetTest.java
new file mode 100644
index 0000000..abf963d
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartDatasetTest.java
@@ -0,0 +1,335 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartDatasetTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:14 $
+ * by $Author: davidwithers $
+ * Created on 4 Aug 2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class MartDatasetTest extends TestCase {
+
+ private String displayName;
+
+ private String name;
+
+ private String type;
+
+ private int initialBatchSize;
+
+ private int maximumBatchSize;
+
+ private boolean visible;
+
+ private String interfaceValue;
+
+ private String modified;
+
+ private MartURLLocation martUrlLocation;
+
+ private MartDataset martDataset;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ displayName = "dataset-display-name";
+ name = "dataset-name";
+ type = "type";
+ initialBatchSize = 1;
+ maximumBatchSize = 2;
+ visible = true;
+ interfaceValue = "interface";
+ modified = "modified";
+ martUrlLocation = new MartURLLocation();
+ martUrlLocation.setDefault(true);
+ martUrlLocation.setDisplayName("location-display-name");
+ martUrlLocation.setHost("host");
+ martUrlLocation.setName("location-name");
+ martUrlLocation.setPort(42);
+ martUrlLocation.setServerVirtualSchema("server-virtual-schema");
+ martUrlLocation.setVirtualSchema("virtual-schema");
+ martUrlLocation.setVisible(false);
+ martDataset = new MartDataset();
+ martDataset.setDisplayName(displayName);
+ martDataset.setInitialBatchSize(initialBatchSize);
+ martDataset.setMartURLLocation(martUrlLocation);
+ martDataset.setMaximumBatchSize(maximumBatchSize);
+ martDataset.setName(name);
+ martDataset.setType(type);
+ martDataset.setVisible(visible);
+ martDataset.setInterface(interfaceValue);
+ martDataset.setModified(modified);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#hashCode()}.
+ */
+ public void testHashCode() {
+ assertEquals(martDataset.hashCode(), martDataset.hashCode());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getDisplayName()}.
+ */
+ public void testGetDisplayName() {
+ assertEquals(martDataset.getDisplayName(), displayName);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setDisplayName(java.lang.String)}.
+ */
+ public void testSetDisplayName() {
+ martDataset.setDisplayName("new" + displayName);
+ assertEquals(martDataset.getDisplayName(), "new" + displayName);
+ martDataset.setDisplayName(null);
+ assertNull(martDataset.getDisplayName());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getInitialBatchSize()}.
+ */
+ public void testGetInitialBatchSize() {
+ assertEquals(martDataset.getInitialBatchSize(), initialBatchSize);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setInitialBatchSize(long)}.
+ */
+ public void testSetInitialBatchSize() {
+ martDataset.setInitialBatchSize(1 + initialBatchSize);
+ assertEquals(martDataset.getInitialBatchSize(), 1 + initialBatchSize);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getMaximumBatchSize()}.
+ */
+ public void testGetMaximumBatchSize() {
+ assertEquals(martDataset.getMaximumBatchSize(), maximumBatchSize);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setMaximumBatchSize(long)}.
+ */
+ public void testSetMaximumBatchSize() {
+ martDataset.setMaximumBatchSize(1 + maximumBatchSize);
+ assertEquals(martDataset.getMaximumBatchSize(), 1 + maximumBatchSize);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#getName()}.
+ */
+ public void testGetName() {
+ assertEquals(martDataset.getName(), name);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setName(java.lang.String)}.
+ */
+ public void testSetName() {
+ martDataset.setName("new" + name);
+ assertEquals(martDataset.getName(), "new" + name);
+ martDataset.setName(null);
+ assertNull(martDataset.getName());
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#getType()}.
+ */
+ public void testGetType() {
+ assertEquals(martDataset.getType(), type);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setType(java.lang.String)}.
+ */
+ public void testSetType() {
+ martDataset.setType("new" + type);
+ assertEquals(martDataset.getType(), "new" + type);
+ martDataset.setType(null);
+ assertNull(martDataset.getType());
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#isVisible()}.
+ */
+ public void testIsVisible() {
+ assertEquals(martDataset.isVisible(), visible);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setVisible(boolean)}.
+ */
+ public void testSetVisible() {
+ martDataset.setVisible(!visible);
+ assertEquals(martDataset.isVisible(), !visible);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#getInterface()}.
+ */
+ public void testGetInterface() {
+ assertEquals(martDataset.getInterface(), interfaceValue);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setInterface(java.lang.String)}.
+ */
+ public void testSetInterface() {
+ martDataset.setInterface("new" + interfaceValue);
+ assertEquals(martDataset.getInterface(), "new" + interfaceValue);
+ martDataset.setInterface(null);
+ assertNull(martDataset.getInterface());
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#getModified()}.
+ */
+ public void testGetModified() {
+ assertEquals(martDataset.getModified(), modified);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setModified(java.lang.String)}.
+ */
+ public void testSetModified() {
+ martDataset.setModified("new" + modified);
+ assertEquals(martDataset.getModified(), "new" + modified);
+ martDataset.setModified(null);
+ assertNull(martDataset.getModified());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getMartURLLocation()}.
+ */
+ public void testGetMartURLLocation() {
+ assertEquals(martDataset.getMartURLLocation(), martUrlLocation);
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#setMartURLLocation(org.biomart.martservice.MartURLLocation)}.
+ */
+ public void testSetMartURLLocation() {
+ martUrlLocation = new MartURLLocation();
+ martDataset.setMartURLLocation(martUrlLocation);
+ assertEquals(martDataset.getMartURLLocation(), martUrlLocation);
+ martDataset.setMartURLLocation(null);
+ assertNull(martDataset.getMartURLLocation());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getVirtualSchema()}.
+ */
+ public void testGetVirtualSchema() {
+ assertEquals(martDataset.getVirtualSchema(), martDataset
+ .getMartURLLocation().getVirtualSchema());
+ martDataset.setMartURLLocation(null);
+ assertNull(martDataset.getVirtualSchema());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getQualifiedName()}.
+ */
+ public void testGetQualifiedName() {
+ assertEquals(martDataset.getQualifiedName(), martDataset
+ .getVirtualSchema()
+ + "." + name);
+ martDataset.setMartURLLocation(null);
+ assertEquals(martDataset.getQualifiedName(), name);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartDataset#toString()}.
+ */
+ public void testToString() {
+ assertEquals(martDataset.toString(), martDataset.getDisplayName());
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#equals(java.lang.Object)}.
+ */
+ public void testEqualsObject() {
+ MartDataset martDataset2 = new MartDataset();
+ martDataset2.setDisplayName(displayName);
+ martDataset2.setInitialBatchSize(initialBatchSize);
+ martDataset2.setMartURLLocation(martUrlLocation);
+ martDataset2.setMaximumBatchSize(maximumBatchSize);
+ martDataset2.setName(name);
+ martDataset2.setType(type);
+ martDataset2.setVisible(visible);
+
+ assertTrue(martDataset.equals(martDataset));
+ assertTrue(martDataset.equals(martDataset2));
+ assertTrue(martDataset2.equals(martDataset));
+ assertFalse(martDataset.equals(null));
+ assertFalse(martDataset.equals(new Object()));
+ assertFalse(martDataset.equals(new MartRegistry()));
+ martDataset2.setName("new" + name);
+ assertFalse(martDataset.equals(martDataset2));
+ assertFalse(martDataset2.equals(martDataset));
+ }
+
+ /**
+ * Test method for
+ * {@link org.biomart.martservice.MartDataset#getDisplayComparator()}.
+ */
+ public void testGetDisplayComparator() {
+ MartDataset martDataset2 = new MartDataset();
+ martDataset2.setDisplayName(displayName);
+ assertEquals(MartDataset.getDisplayComparator().compare(martDataset, martDataset2), 0);
+ martDataset2.setDisplayName("new" + displayName);
+ assertTrue(MartDataset.getDisplayComparator().compare(martDataset, martDataset2) != 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartRegistryTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartRegistryTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartRegistryTest.java
new file mode 100644
index 0000000..5766d60
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartRegistryTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartRegistryTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:14 $
+ * by $Author: davidwithers $
+ * Created on 4 Aug 2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class MartRegistryTest extends TestCase {
+
+ private MartURLLocation martUrlLocation;
+
+ private MartRegistry martRegistry;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ martUrlLocation = new MartURLLocation();
+ martUrlLocation.setDefault(true);
+ martUrlLocation.setDisplayName("location-display-name");
+ martUrlLocation.setHost("host");
+ martUrlLocation.setName("location-name");
+ martUrlLocation.setPort(42);
+ martUrlLocation.setServerVirtualSchema("server-virtual-schema");
+ martUrlLocation.setVirtualSchema("virtual-schema");
+ martUrlLocation.setVisible(false);
+ martRegistry = new MartRegistry();
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartRegistry#hashCode()}.
+ */
+ public void testHashCode() {
+ MartRegistry martRegistry2 = new MartRegistry();
+ martRegistry.addMartURLLocation(martUrlLocation);
+ martRegistry2.addMartURLLocation(martUrlLocation);
+ assertEquals(martRegistry.hashCode(), martRegistry.hashCode());
+ assertEquals(martRegistry.hashCode(), martRegistry2.hashCode());
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartRegistry#getMartURLLocations()}.
+ */
+ public void testGetMartURLLocations() {
+ assertEquals(martRegistry.getMartURLLocations().length, 0);
+ martRegistry.addMartURLLocation(martUrlLocation);
+ assertEquals(martRegistry.getMartURLLocations()[0], martUrlLocation);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartRegistry#addMartURLLocation(org.biomart.martservice.MartURLLocation)}.
+ */
+ public void testAddMartURLLocation() {
+ martRegistry.addMartURLLocation(martUrlLocation);
+ MartURLLocation[] martURLLocations = martRegistry.getMartURLLocations();
+ assertEquals(martURLLocations[martURLLocations.length - 1], martUrlLocation);
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartRegistry#equals(java.lang.Object)}.
+ */
+ public void testEqualsObject() {
+ MartRegistry martRegistry2 = new MartRegistry();
+ martRegistry.addMartURLLocation(martUrlLocation);
+ martRegistry2.addMartURLLocation(martUrlLocation);
+
+ assertTrue(martRegistry.equals(martRegistry));
+ assertTrue(martRegistry.equals(martRegistry2));
+ assertTrue(martRegistry2.equals(martRegistry));
+ assertFalse(martRegistry.equals(null));
+ assertFalse(martRegistry.equals(new Object()));
+ assertFalse(martRegistry.equals(new MartRegistry()));
+ martRegistry2.addMartURLLocation(martUrlLocation);
+ assertFalse(martRegistry.equals(martRegistry2));
+ assertFalse(martRegistry2.equals(martRegistry));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceUtilsTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceUtilsTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceUtilsTest.java
new file mode 100644
index 0000000..d938440
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceUtilsTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceUtilsTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/02/22 18:31:56 $
+ * by $Author: davidwithers $
+ * Created on 22 Feb 2007
+ *****************************************************************/
+package org.biomart.martservice;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author David Withers
+ */
+public class MartServiceUtilsTest {
+
+ /**
+ * Test method for {@link org.biomart.martservice.MartServiceUtils#isProxyHost(java.lang.String)}.
+ */
+ @Test
+ public void testIsProxyHost() {
+ System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1|*.mydomain.com|192.168.1.*");
+ assertFalse(MartServiceUtils.isProxyHost("http://localhost/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://localhost:8080/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://127.0.0.1/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://www.mydomain.com/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://www.sub.mydomain.com/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://192.168.1.1/"));
+ assertFalse(MartServiceUtils.isProxyHost("http://192.168.1.2/"));
+ assertTrue(MartServiceUtils.isProxyHost("http://www.mydomain.co.uk/"));
+ assertTrue(MartServiceUtils.isProxyHost("http://192.168.2.1/"));
+ assertTrue(MartServiceUtils.isProxyHost("http://127.0.0.2/"));
+ assertTrue(MartServiceUtils.isProxyHost("http://nonlocalhost/"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceXMLHandlerTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceXMLHandlerTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceXMLHandlerTest.java
new file mode 100644
index 0000000..4c4dded
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartServiceXMLHandlerTest.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceXMLHandlerTest.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/04 14:16:00 $
+ * by $Author: davidwithers $
+ * Created on 02-Jun-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+
+/**
+ *
+ * @author David Withers
+ */
+public class MartServiceXMLHandlerTest extends TestCase {
+ private XMLOutputter xmlOutputter;
+
+ private SAXBuilder saxBuilder;
+
+ private Namespace namespace;
+
+ private MartService martService;
+
+ private String martServiceXML;
+
+ private MartURLLocation martUrlLocation;
+
+ private String martUrlLocationXML;
+
+ private MartDataset martDataset;
+
+ private String martDatasetXML;
+
+ private MartRegistry martRegistry;
+
+ private String martRegistryXML;
+
+ private String martRegistryXML2;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ xmlOutputter = new XMLOutputter();
+ saxBuilder = new SAXBuilder();
+ namespace = Namespace.getNamespace("test-namespace");
+ martService = MartService.getMartService("url-location");
+ martServiceXML = "<MartService xmlns=\"test-namespace\" location=\"url-location\" />";
+ martUrlLocation = new MartURLLocation();
+ martUrlLocation.setDefault(true);
+ martUrlLocation.setDisplayName("location-display-name");
+ martUrlLocation.setHost("host");
+ martUrlLocation.setName("location-name");
+ martUrlLocation.setPort(42);
+ martUrlLocation.setServerVirtualSchema("server-virtual-schema");
+ martUrlLocation.setVirtualSchema("virtual-schema");
+ martUrlLocation.setVisible(false);
+ martUrlLocation.setRedirect(true);
+ martUrlLocationXML = "<MartURLLocation xmlns=\"test-namespace\" default=\"1\" displayName=\"location-display-name\" host=\"host\" name=\"location-name\" port=\"42\" serverVirtualSchema=\"server-virtual-schema\" virtualSchema=\"virtual-schema\" visible=\"0\" redirect=\"1\" />";
+ martDataset = new MartDataset();
+ martDataset.setDisplayName("dataset-display-name");
+ martDataset.setInitialBatchSize(1);
+ martDataset.setMartURLLocation(martUrlLocation);
+ martDataset.setMaximumBatchSize(2);
+ martDataset.setName("dataset-name");
+ martDataset.setType("type");
+ martDataset.setVisible(true);
+ martDataset.setInterface("interface");
+ martDataset.setModified("modified");
+ martDatasetXML = "<MartDataset xmlns=\"test-namespace\" displayName=\"dataset-display-name\" name=\"dataset-name\" type=\"type\" initialBatchSize=\"1\" maximumBatchSize=\"2\" visible=\"true\" interface=\"interface\" modified=\"modified\"><MartURLLocation default=\"1\" displayName=\"location-display-name\" host=\"host\" name=\"location-name\" port=\"42\" serverVirtualSchema=\"server-virtual-schema\" virtualSchema=\"virtual-schema\" visible=\"0\" redirect=\"1\" /></MartDataset>";
+ martRegistry = new MartRegistry();
+ martRegistry.addMartURLLocation(martUrlLocation);
+ martRegistryXML = "<MartRegistry xmlns=\"test-namespace\" ><virtualSchema xmlns=\"test-namespace\" name=\"virtual-schema\" visible=\"0\"><MartURLLocation xmlns=\"test-namespace\" default=\"1\" displayName=\"location-display-name\" host=\"host\" name=\"location-name\" port=\"42\" serverVirtualSchema=\"server-virtual-schema\" visible=\"0\" redirect=\"1\" /></virtualSchema></MartRegistry>";
+ martRegistryXML2 = "<MartRegistry xmlns=\"test-namespace\" ><virtualSchema xmlns=\"test-namespace\" name=\"default\" visible=\"0\"><MartURLLocation xmlns=\"test-namespace\" default=\"1\" displayName=\"location-display-name\" host=\"host\" name=\"location-name\" port=\"42\" serverVirtualSchema=\"server-virtual-schema\" visible=\"0\" redirect=\"1\" /></virtualSchema></MartRegistry>";
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.martServiceToElement(MartService,
+ * Namespace)'
+ */
+ public void testMartServiceToElement() {
+ Element element = MartServiceXMLHandler.martServiceToElement(
+ martService, namespace);
+ assertEquals(xmlOutputter.outputString(element), martServiceXML);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.elementToMartService(Element)'
+ */
+ public void testElementToMartService() throws JDOMException, IOException {
+ Element element = saxBuilder.build(new StringReader(martServiceXML))
+ .getRootElement();
+ assertEquals(MartServiceXMLHandler.elementToMartService(element),
+ martService);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.datasetToElement(MartDataset,
+ * Namespace)'
+ */
+ public void testDatasetToElement() {
+ Element element = MartServiceXMLHandler.datasetToElement(martDataset,
+ namespace);
+ assertEquals(xmlOutputter.outputString(element), martDatasetXML);
+// System.out.println(new XMLOutputter().outputString(element));
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.elementToDataset(Element,
+ * Namespace)'
+ */
+ public void testElementToDataset() throws JDOMException, IOException {
+ Element element = saxBuilder.build(new StringReader(martDatasetXML))
+ .getRootElement();
+ assertEquals(
+ MartServiceXMLHandler.elementToDataset(element, namespace),
+ martDataset);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.elementToRegistry(Element,
+ * Namespace)'
+ */
+ public void testElementToRegistry() throws JDOMException, IOException {
+ Element element = saxBuilder.build(new StringReader(martRegistryXML))
+ .getRootElement();
+ assertEquals(MartServiceXMLHandler
+ .elementToRegistry(element, namespace), martRegistry);
+
+ martUrlLocation.setVirtualSchema("default");
+ element = saxBuilder.build(new StringReader(martRegistryXML2))
+ .getRootElement();
+ assertEquals(MartServiceXMLHandler
+ .elementToRegistry(element, namespace), martRegistry);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.locationToElement(MartURLLocation,
+ * Namespace)'
+ */
+ public void testLocationToElement() {
+ Element element = MartServiceXMLHandler.locationToElement(
+ martUrlLocation, namespace);
+ assertEquals(xmlOutputter.outputString(element), martUrlLocationXML);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.elementToLocation(Element)'
+ */
+ public void testElementToLocation() throws JDOMException, IOException {
+ Element element = saxBuilder
+ .build(new StringReader(martUrlLocationXML)).getRootElement();
+ assertEquals(MartServiceXMLHandler.elementToLocation(element),
+ martUrlLocation);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.elementToMartQuery(Element,
+ * Namespace)'
+ */
+ public void testElementToMartQuery() {
+
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.MartServiceXMLHandler.martQueryToElement(MartQuery,
+ * Namespace)'
+ */
+ public void testMartQueryToElement() {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartURLLocationTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartURLLocationTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartURLLocationTest.java
new file mode 100644
index 0000000..aa5ad8a
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/MartURLLocationTest.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartURLLocationTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:14 $
+ * by $Author: davidwithers $
+ * Created on 02-Jun-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class MartURLLocationTest extends TestCase {
+ private MartURLLocation martURLLocation;
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ martURLLocation = new MartURLLocation();
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.isDefault()'
+ */
+ public void testIsDefault() {
+ assertFalse(martURLLocation.isDefault());
+ martURLLocation.setDefault(true);
+ assertTrue(martURLLocation.isDefault());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setDefault(boolean)'
+ */
+ public void testSetDefault() {
+ martURLLocation.setDefault(true);
+ assertTrue(martURLLocation.isDefault());
+ martURLLocation.setDefault(false);
+ assertFalse(martURLLocation.isDefault());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getDisplayName()'
+ */
+ public void testGetDisplayName() {
+ assertNull(martURLLocation.getDisplayName());
+ martURLLocation.setDisplayName("DisplayName");
+ assertEquals(martURLLocation.getDisplayName(), "DisplayName");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setDisplayName(String)'
+ */
+ public void testSetDisplayName() {
+ martURLLocation.setDisplayName("DisplayName");
+ assertEquals(martURLLocation.getDisplayName(), "DisplayName");
+ martURLLocation.setDisplayName(null);
+ assertNull(martURLLocation.getDisplayName());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getHost()'
+ */
+ public void testGetHost() {
+ assertNull(martURLLocation.getHost());
+ martURLLocation.setHost("Host");
+ assertEquals(martURLLocation.getHost(), "Host");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setHost(String)'
+ */
+ public void testSetHost() {
+ martURLLocation.setHost("Host");
+ assertEquals(martURLLocation.getHost(), "Host");
+ martURLLocation.setHost(null);
+ assertNull(martURLLocation.getHost());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getName()'
+ */
+ public void testGetName() {
+ assertNull(martURLLocation.getName());
+ martURLLocation.setName("Name");
+ assertEquals(martURLLocation.getName(), "Name");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setName(String)'
+ */
+ public void testSetName() {
+ martURLLocation.setName("Name");
+ assertEquals(martURLLocation.getName(), "Name");
+ martURLLocation.setName(null);
+ assertNull(martURLLocation.getName());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getPort()'
+ */
+ public void testGetPort() {
+ assertEquals(martURLLocation.getPort(), 0);
+ martURLLocation.setPort(-1);
+ assertEquals(martURLLocation.getPort(), -1);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setPort(int)'
+ */
+ public void testSetPort() {
+ martURLLocation.setPort(-1);
+ assertEquals(martURLLocation.getPort(), -1);
+ martURLLocation.setPort(0);
+ assertEquals(martURLLocation.getPort(), 0);
+ martURLLocation.setPort(1);
+ assertEquals(martURLLocation.getPort(), 1);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getServerVirtualSchema()'
+ */
+ public void testGetServerVirtualSchema() {
+ assertNull(martURLLocation.getServerVirtualSchema());
+ martURLLocation.setServerVirtualSchema("ServerVirtualSchema");
+ assertEquals(martURLLocation.getServerVirtualSchema(), "ServerVirtualSchema");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setServerVirtualSchema(String)'
+ */
+ public void testSetServerVirtualSchema() {
+ martURLLocation.setServerVirtualSchema("ServerVirtualSchema");
+ assertEquals(martURLLocation.getServerVirtualSchema(), "ServerVirtualSchema");
+ martURLLocation.setServerVirtualSchema(null);
+ assertNull(martURLLocation.getServerVirtualSchema());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getVirtualSchema()'
+ */
+ public void testGetVirtualSchema() {
+ assertNull(martURLLocation.getVirtualSchema());
+ martURLLocation.setVirtualSchema("VirtualSchema");
+ assertEquals(martURLLocation.getVirtualSchema(), "VirtualSchema");
+
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setVirtualSchema(String)'
+ */
+ public void testSetVirtualSchema() {
+ martURLLocation.setVirtualSchema("VirtualSchema");
+ assertEquals(martURLLocation.getVirtualSchema(), "VirtualSchema");
+ martURLLocation.setVirtualSchema(null);
+ assertNull(martURLLocation.getVirtualSchema());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.isVisible()'
+ */
+ public void testIsVisible() {
+ assertFalse(martURLLocation.isVisible());
+ martURLLocation.setVisible(true);
+ assertTrue(martURLLocation.isVisible());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.setVisible(boolean)'
+ */
+ public void testSetVisible() {
+ martURLLocation.setVisible(true);
+ assertTrue(martURLLocation.isVisible());
+ martURLLocation.setVisible(false);
+ assertFalse(martURLLocation.isVisible());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.getType()'
+ */
+ public void testGetType() {
+ assertEquals(martURLLocation.getType(), "URL");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.MartURLLocation.toString()'
+ */
+ public void testToString() {
+ martURLLocation.setDisplayName("DisplayName");
+ assertEquals(martURLLocation.toString(), "DisplayName");
+ }
+
+ public void testHashCode() {
+ MartURLLocation martURLLocation2 = new MartURLLocation();
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setDefault(true);
+ martURLLocation2.setDefault(true);
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setDisplayName("DisplayName");
+ martURLLocation2.setDisplayName("DisplayName");
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setHost("Host");
+ martURLLocation2.setHost("Host");
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setName("Name");
+ martURLLocation2.setName("Name");
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setPort(-1);
+ martURLLocation2.setPort(-1);
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setServerVirtualSchema("ServerVirtualSchema");
+ martURLLocation2.setServerVirtualSchema("ServerVirtualSchema");
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setVirtualSchema("VirtualSchema");
+ martURLLocation2.setVirtualSchema("VirtualSchema");
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setVisible(true);
+ martURLLocation2.setVisible(true);
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+ martURLLocation.setVisible(true);
+ martURLLocation2.setVisible(true);
+ assertEquals(martURLLocation.hashCode(), martURLLocation2.hashCode());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/event/QueryComponentEventTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/event/QueryComponentEventTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/event/QueryComponentEventTest.java
new file mode 100644
index 0000000..c22d8e2
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/event/QueryComponentEventTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryComponentEventTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:15 $
+ * by $Author: davidwithers $
+ * Created on 06-Jun-2006
+ *****************************************************************/
+package org.biomart.martservice.config.event;
+
+import org.biomart.martservice.MartDataset;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class QueryComponentEventTest extends TestCase {
+ private QueryComponentEvent queryComponentEvent;
+
+ private QueryComponentEvent nullQueryComponentEvent;
+
+ private Object source;
+
+ private String name;
+
+ private MartDataset martDataset;
+
+ private String value;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ source = "source";
+ name = "name";
+ martDataset = new MartDataset();
+ value = "value";
+ queryComponentEvent = new QueryComponentEvent(source, name, martDataset, value);
+ nullQueryComponentEvent = new QueryComponentEvent(source, null, null, null);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.config.event.QueryComponentEvent.QueryComponentEvent(Object,
+ * String, MartDataset)'
+ */
+ public void testQueryComponentEventObjectStringMartDataset() {
+ QueryComponentEvent event = new QueryComponentEvent(source, name, martDataset);
+ assertSame(event.getSource(), source);
+ assertEquals(event.getName(), name);
+ assertEquals(event.getDataset(), martDataset);
+ assertNull(event.getValue());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.config.event.QueryComponentEvent.QueryComponentEvent(Object,
+ * String, MartDataset, String)'
+ */
+ public void testQueryComponentEventObjectStringMartDatasetString() {
+ QueryComponentEvent event = new QueryComponentEvent(source, name, martDataset, value);
+ assertSame(event.getSource(), source);
+ assertEquals(event.getName(), name);
+ assertEquals(event.getDataset(), martDataset);
+ assertEquals(event.getValue(), value);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.config.event.QueryComponentEvent.getName()'
+ */
+ public void testGetName() {
+ assertEquals(queryComponentEvent.getName(), name);
+ assertNull(nullQueryComponentEvent.getName());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.config.event.QueryComponentEvent.getDataset()'
+ */
+ public void testGetDataset() {
+ assertEquals(queryComponentEvent.getDataset(), martDataset);
+ assertNull(nullQueryComponentEvent.getDataset());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.config.event.QueryComponentEvent.getValue()'
+ */
+ public void testGetValue() {
+ assertEquals(queryComponentEvent.getValue(), value);
+ assertNull(nullQueryComponentEvent.getValue());
+ }
+
+ /*
+ * Test method for 'java.util.EventObject.getSource()'
+ */
+ public void testGetSource() {
+ assertSame(queryComponentEvent.getSource(), source);
+ assertSame(nullQueryComponentEvent.getSource(), source);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/ui/MartServiceIconsTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/ui/MartServiceIconsTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/ui/MartServiceIconsTest.java
new file mode 100644
index 0000000..2236f37
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/config/ui/MartServiceIconsTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceIconsTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:16 $
+ * by $Author: davidwithers $
+ * Created on 24-Aug-2006
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author witherd5
+ */
+public class MartServiceIconsTest extends TestCase {
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Test method for {@link org.biomart.martservice.config.ui.MartServiceIcons#getIcon(java.lang.String)}.
+ */
+ public void testGetIcon() {
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_3utr"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_5utr"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_cdna"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_coding_gene_flank"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_coding_transcript_flank"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_coding"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_gene_exon_intron"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_gene_exon"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_gene_flank"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_peptide"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_transcript_exon_intron"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_transcript_exon"));
+ assertNotNull(MartServiceIcons.getIcon("gene_schematic_transcript_flank"));
+ assertNotNull(MartServiceIcons.getIcon("expand"));
+ assertNotNull(MartServiceIcons.getIcon("contract"));
+ assertNull(MartServiceIcons.getIcon("something else"));
+ assertNull(MartServiceIcons.getIcon(""));
+ assertNull(MartServiceIcons.getIcon(null));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/AttributeTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/AttributeTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/AttributeTest.java
new file mode 100644
index 0000000..5ac4c9e
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/AttributeTest.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: AttributeTest.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/03/04 16:43:40 $
+ * by $Author: davidwithers $
+ * Created on 02-May-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ *
+ * @author David Withers
+ */
+public class AttributeTest {
+ private String attributeName;
+
+ private String attributes;
+
+ private Dataset dataset;
+
+ private Attribute attribute;
+
+ @Before
+ public void setUp() throws Exception {
+ attributeName = "attribute name";
+ attributes = "attributes";
+ dataset = new Dataset("dataset name");
+ attribute = new Attribute(attributeName);
+ }
+
+ @Test
+ public void AttributeString() {
+ Attribute attribute = new Attribute(attributeName);
+ assertEquals("Name should be '" + attributeName + "'", attribute
+ .getName(), attributeName);
+ }
+
+ @Test
+ public void AttributeAttribute() {
+ attribute.setContainingDataset(dataset);
+ Attribute copy = new Attribute(attribute);
+ assertEquals(attribute.getName(), copy.getName());
+ assertNull(copy.getContainingDataset());
+ }
+
+ @Test
+ public final void getName() {
+ assertEquals("Name should be '" + attributeName + "'", attribute
+ .getName(), attributeName);
+ }
+
+ @Test (expected=IllegalArgumentException.class)
+ public final void setName() {
+ String newName = "new attribute name";
+ attribute.setName(newName);
+ assertEquals("Name should be '" + newName + "'", attribute.getName(),
+ newName);
+ attribute.setName(null);
+ }
+
+ @Test
+ public final void getQualifiedName() {
+ assertEquals("Qualified name should be '" + attributeName + "'",
+ attribute.getQualifiedName(), attributeName);
+
+ String qualifiedName = dataset.getName() + "." + attributeName;
+ attribute.setContainingDataset(dataset);
+ assertEquals("Qualified name should be '" + qualifiedName + "'",
+ attribute.getQualifiedName(), qualifiedName);
+
+ dataset.setName("new dataset name");
+ qualifiedName = dataset.getName() + "." + attributeName;
+ attribute.setContainingDataset(dataset);
+ assertEquals("Qualified name should be '" + qualifiedName + "'",
+ attribute.getQualifiedName(), qualifiedName);
+
+ attribute.setContainingDataset(null);
+ assertEquals("Qualified name should be '" + attributeName + "'",
+ attribute.getQualifiedName(), attributeName);
+ }
+
+ @Test
+ public void getAttributes() {
+ assertNull(attribute.getAttributes());
+ attribute.setAttributes(attributes);
+ assertEquals("Attributes should be '" + attributes + "'", attribute
+ .getAttributes(), attributes);
+ }
+
+ @Test
+ public void setAttributes() {
+ String newAttributes = "new attributes";
+ attribute.setAttributes(newAttributes);
+ assertEquals("Attributes should be '" + newAttributes + "'", attribute.getAttributes(),
+ newAttributes);
+ attribute.setAttributes(null);
+ assertNull(attribute.getAttributes());
+ }
+
+ @Test
+ public void testGetAttributesCount() {
+ assertEquals(attribute.getAttributesCount(), 0);
+ attribute.setAttributes("a");
+ assertEquals(attribute.getAttributesCount(), 1);
+ attribute.setAttributes("a,b,c");
+ assertEquals(attribute.getAttributesCount(), 3);
+ attribute.setAttributes(null);
+ assertEquals(attribute.getAttributesCount(), 0);
+ }
+
+ @Test
+ public void getContainingDataset() {
+ assertNull(attribute.getContainingDataset());
+ dataset.addAttribute(attribute);
+ assertEquals(attribute.getContainingDataset(), dataset);
+ }
+
+ @Test
+ public void setContainingDataset() {
+ attribute.setContainingDataset(dataset);
+ assertEquals(attribute.getContainingDataset(), dataset);
+ attribute.setContainingDataset(null);
+ assertNull(attribute.getContainingDataset());
+ }
+
+ @Test
+ public void hashCodeTest() {
+ Attribute attribute2 = new Attribute(attributeName);
+ assertEquals(attribute.hashCode(), attribute.hashCode());
+ assertEquals(attribute.hashCode(), attribute2.hashCode());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/DatasetTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/DatasetTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/DatasetTest.java
new file mode 100644
index 0000000..374ce5d
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/DatasetTest.java
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: DatasetTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:10 $
+ * by $Author: davidwithers $
+ * Created on 03-May-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class DatasetTest extends TestCase {
+ private String attributeName;
+
+ private Attribute attribute;
+
+ private String filterName;
+
+ private String filterValue;
+
+ private Filter filter;
+
+// private Link link;
+
+ private String datasetName;
+
+ private Dataset dataset;
+
+ private Query query;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ attributeName = "attribute name";
+ attribute = new Attribute(attributeName);
+
+ filterName = "filter name";
+ filterValue = "filter value";
+ filter = new Filter(filterName, filterValue);
+
+// link = new Link("source", "target", "id");
+
+ datasetName = "dataset name";
+ dataset = new Dataset(datasetName);
+
+ query = new Query("default");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.Dataset(String)'
+ */
+ public final void testDatasetString() {
+ Dataset dataset = new Dataset(datasetName);
+ assertEquals("Name should be '" + datasetName + "'", dataset.getName(),
+ datasetName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.Dataset(Dataset)'
+ */
+ public final void testDatasetDataset() {
+ dataset.addAttribute(attribute);
+ dataset.addFilter(filter);
+ Dataset copy = new Dataset(dataset);
+ assertEquals("Name should be '" + datasetName + "'", copy.getName(),
+ datasetName);
+ assertEquals(copy.getAttributes().size(), 1);
+ assertEquals(((Attribute) copy.getAttributes().get(0)).getName(),
+ attribute.getName());
+ assertEquals(copy.getFilters().size(), 1);
+ assertEquals(((Filter) copy.getFilters().get(0)).getName(), filter
+ .getName());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.getName()'
+ */
+ public final void testGetName() {
+ assertEquals("Name should be '" + datasetName + "'", dataset.getName(),
+ datasetName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.setName(String)'
+ */
+ public final void testSetName() {
+ String newName = "new dataset name";
+ filter.setName(newName);
+ assertEquals("Name should be '" + newName + "'", filter.getName(),
+ newName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.getAttributes()'
+ */
+ public final void testGetAttributes() {
+ assertEquals(dataset.getAttributes().size(), 0);
+ dataset.addAttribute(attribute);
+ assertEquals(dataset.getAttributes().size(), 1);
+ assertEquals(dataset.getAttributes().get(0), attribute);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.addAttribute(Attribute)'
+ */
+ public final void testAddAttribute() {
+ assertTrue(dataset.addAttribute(attribute));
+ assertFalse(dataset.addAttribute(attribute));
+ assertEquals(dataset.getAttributes().size(), 1);
+ assertEquals(dataset.getAttributes().get(0), attribute);
+ query.addDataset(dataset);
+ assertTrue(dataset.addAttribute(new Attribute("new attribute")));
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.addAttributes(Attribute[])'
+ */
+ public final void testAddAttributes() {
+ dataset.addAttributes(new Attribute[] {});
+ assertEquals(dataset.getAttributes().size(), 0);
+ dataset.addAttributes(new Attribute[] { attribute });
+ assertEquals(dataset.getAttributes().size(), 1);
+ assertEquals(dataset.getAttributes().get(0), attribute);
+ Attribute anotherAttribute = new Attribute("another attribute");
+ dataset.addAttributes(new Attribute[] { attribute, anotherAttribute });
+ assertEquals(dataset.getAttributes().size(), 2);
+ assertEquals(dataset.getAttributes().get(0), attribute);
+ assertEquals(dataset.getAttributes().get(1), anotherAttribute);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.hasAttribute(Attribute)'
+ */
+ public final void testHasAttribute() {
+ assertFalse(dataset.hasAttribute(attribute));
+ dataset.addAttribute(attribute);
+ assertTrue(dataset.hasAttribute(attribute));
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.hasAttributes()'
+ */
+ public final void testHasAttributes() {
+ assertFalse(dataset.hasAttributes());
+ dataset.addAttribute(attribute);
+ assertTrue(dataset.hasAttributes());
+ dataset.removeAttribute(attribute);
+ assertFalse(dataset.hasAttributes());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.removeAttribute(Attribute)'
+ */
+ public final void testRemoveAttribute() {
+ assertFalse(dataset.removeAttribute(attribute));
+ dataset.addAttribute(attribute);
+ assertTrue(dataset.removeAttribute(attribute));
+ assertEquals(dataset.getAttributes().size(), 0);
+ query.addDataset(dataset);
+ dataset.addAttribute(attribute);
+ assertTrue(dataset.removeAttribute(attribute));
+ }
+
+ public void testRemoveAllAttributes() {
+ dataset.removeAllAttributes();
+ assertFalse(dataset.hasAttributes());
+ dataset.addAttribute(attribute);
+ dataset.removeAllAttributes();
+ assertFalse(dataset.hasAttributes());
+ dataset.addAttributes(new Attribute[] { attribute, new Attribute("new attribute") });
+ dataset.removeAllAttributes();
+ assertFalse(dataset.hasAttributes());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.getFilters()'
+ */
+ public final void testGetFilters() {
+ assertEquals(dataset.getFilters().size(), 0);
+ dataset.addFilter(filter);
+ assertEquals(dataset.getFilters().size(), 1);
+ assertEquals(dataset.getFilters().get(0), filter);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.addFilter(Filter)'
+ */
+ public final void testAddFilter() {
+ assertTrue(dataset.addFilter(filter));
+ assertFalse(dataset.addFilter(filter));
+ assertEquals(dataset.getFilters().size(), 1);
+ assertEquals(dataset.getFilters().get(0), filter);
+ query.addDataset(dataset);
+ assertTrue(dataset.addFilter(new Filter("new filter")));
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.addFilters(Filter[])'
+ */
+ public final void testAddFilters() {
+ dataset.addFilters(new Filter[] {});
+ assertEquals(dataset.getFilters().size(), 0);
+ dataset.addFilters(new Filter[] { filter });
+ assertEquals(dataset.getFilters().size(), 1);
+ assertEquals(dataset.getFilters().get(0), filter);
+ Filter anotherFilter = new Filter("another filter");
+ dataset.addFilters(new Filter[] { filter, anotherFilter });
+ assertEquals(dataset.getFilters().size(), 2);
+ assertEquals(dataset.getFilters().get(0), filter);
+ assertEquals(dataset.getFilters().get(1), anotherFilter);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.hasFilter(Filter)'
+ */
+ public final void testHasFilter() {
+ assertFalse(dataset.hasFilter(filter));
+ dataset.addFilter(filter);
+ assertTrue(dataset.hasFilter(filter));
+ dataset.removeFilter(filter);
+ assertFalse(dataset.hasFilters());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Dataset.hasFilters()'
+ */
+ public final void testHasFilters() {
+ assertFalse(dataset.hasFilters());
+ dataset.addFilter(filter);
+ assertTrue(dataset.hasFilters());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Dataset.removeFilter(Filter)'
+ */
+ public final void testRemoveFilter() {
+ assertFalse(dataset.removeFilter(filter));
+ dataset.addFilter(filter);
+ assertTrue(dataset.removeFilter(filter));
+ assertEquals(dataset.getFilters().size(), 0);
+ query.addDataset(dataset);
+ dataset.addFilter(filter);
+ assertTrue(dataset.removeFilter(filter));
+ }
+
+ public void testRemoveAllFilters() {
+ dataset.removeAllFilters();
+ assertFalse(dataset.hasFilters());
+ dataset.addFilter(filter);
+ dataset.removeAllFilters();
+ assertFalse(dataset.hasFilters());
+ dataset.addFilters(new Filter[] { filter, new Filter("new filter") });
+ dataset.removeAllFilters();
+ assertFalse(dataset.hasFilters());
+ }
+
+ public void testGetContainingQuery() {
+ assertNull(dataset.getContainingQuery());
+ query.addDataset(dataset);
+ assertEquals(dataset.getContainingQuery(), query);
+ }
+
+ public void testSetContainingQuery() {
+ dataset.setContainingQuery(query);
+ assertEquals(dataset.getContainingQuery(), query);
+ dataset.setContainingQuery(null);
+ assertNull(dataset.getContainingQuery());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/FilterTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/FilterTest.java b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/FilterTest.java
new file mode 100644
index 0000000..2d0be4e
--- /dev/null
+++ b/taverna-biomart-martservice/src/test/java/org/biomart/martservice/query/FilterTest.java
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: FilterTest.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:10 $
+ * by $Author: davidwithers $
+ * Created on 03-May-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author David Withers
+ */
+public class FilterTest extends TestCase {
+ private String filterName;
+
+ private String filterValue;
+
+ private Dataset dataset;
+
+ private Filter filter;
+
+ private Query query;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ filterName = "filter name";
+ filterValue = "filter value";
+ dataset = new Dataset("dataset name");
+ filter = new Filter(filterName, filterValue);
+ query = new Query("default");
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.Filter(String)'
+ */
+ public final void testFilterString() {
+ Filter filter = new Filter(filterName);
+ assertEquals("Name should be '" + filterName + "'", filter.getName(),
+ filterName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.Filter(String,
+ * String)'
+ */
+ public final void testFilterStringString() {
+ Filter filter = new Filter(filterName, filterValue);
+ assertEquals("Name should be '" + filterName + "'", filter.getName(),
+ filterName);
+ assertEquals("Value should be '" + filterValue + "'",
+ filter.getValue(), filterValue);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.Filter(String,
+ * String, boolean)'
+ */
+ public final void testFilterStringStringBoolean() {
+ Filter filter = new Filter(filterName, filterValue, true);
+ assertEquals("Name should be '" + filterName + "'", filter.getName(),
+ filterName);
+ assertEquals("Value should be '" + filterValue + "'",
+ filter.getValue(), filterValue);
+ assertTrue("isBoolean should be true", filter.isBoolean());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.Filter(Filter)'
+ */
+ public final void testFilterFilter() {
+ filter.setContainingDataset(dataset);
+ Filter copy = new Filter(filter);
+ assertEquals("Name should be '" + filterName + "'", copy.getName(),
+ filterName);
+ assertEquals("Value should be '" + filterValue + "'", copy.getValue(),
+ filterValue);
+ assertFalse("isBoolean should be false", copy.isBoolean());
+ assertNull(copy.getContainingDataset());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Filter.getContainingDataset()'
+ */
+ public final void testGetContainingDataset() {
+ assertNull("Default should be NULL ", filter.getContainingDataset());
+ dataset.addFilter(filter);
+ assertEquals(filter.getContainingDataset(), dataset);
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Filter.setContainingDataset(Dataset)'
+ */
+ public final void testSetContainingDataset() {
+ filter.setContainingDataset(dataset);
+ assertEquals(filter.getContainingDataset(), dataset);
+ filter.setContainingDataset(null);
+ assertNull(filter.getContainingDataset());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.getName()'
+ */
+ public final void testGetName() {
+ assertEquals("Name should be '" + filterName + "'", filter.getName(),
+ filterName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.setName(String)'
+ */
+ public final void testSetName() {
+ String newName = "new filter name";
+ filter.setName(newName);
+ assertEquals("Name should be '" + newName + "'", filter.getName(),
+ newName);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.getValue()'
+ */
+ public final void testGetValue() {
+ assertEquals("Value should be '" + filterValue + "'",
+ filter.getValue(), filterValue);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.setValue(String)'
+ */
+ public final void testSetValue() {
+ String newValue = "new filter value";
+ filter.setValue(newValue);
+ assertEquals("Value should be '" + newValue + "'", filter.getValue(),
+ newValue);
+ filter.setValue(null);
+ assertNull(filter.getValue());
+ filter.setValue(null);
+ assertNull(filter.getValue());
+ filter.setValue(newValue);
+ assertEquals("Value should be '" + newValue + "'", filter.getValue(),
+ newValue);
+ filter.setValue(newValue);
+ assertEquals("Value should be '" + newValue + "'", filter.getValue(),
+ newValue);
+ dataset.addFilter(filter);
+ filter.setValue(null);
+ filter.setValue(newValue);
+ assertEquals("Value should be '" + newValue + "'", filter.getValue(),
+ newValue);
+ query.addDataset(dataset);
+ filter.setValue(null);
+ filter.setValue(newValue);
+ assertEquals("Value should be '" + newValue + "'", filter.getValue(),
+ newValue);
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.isBoolean()'
+ */
+ public final void testIsBoolean() {
+ assertFalse("Default should be false", filter.isBoolean());
+ }
+
+ /*
+ * Test method for
+ * 'org.biomart.martservice.query.Filter.setBoolean(boolean)'
+ */
+ public final void testSetBoolean() {
+ filter.setBoolean(true);
+ assertTrue("isBoolean should be true", filter.isBoolean());
+ }
+
+ /*
+ * Test method for 'org.biomart.martservice.query.Filter.getQualifiedName()'
+ */
+ public final void testGetQualifiedName() {
+ assertEquals("Qualified name should be '" + filterName + "'", filter
+ .getQualifiedName(), filterName);
+
+ String qualifiedName = dataset.getName() + "." + filterName;
+ filter.setContainingDataset(dataset);
+ assertEquals("Qualified name should be '" + qualifiedName + "'", filter
+ .getQualifiedName(), qualifiedName);
+
+ dataset.setName("new dataset name");
+ qualifiedName = dataset.getName() + "." + filterName;
+ filter.setContainingDataset(dataset);
+ assertEquals("Qualified name should be '" + qualifiedName + "'", filter
+ .getQualifiedName(), qualifiedName);
+
+ filter.setContainingDataset(null);
+ assertEquals("Qualified name should be '" + filterName + "'", filter
+ .getQualifiedName(), filterName);
+ }
+
+ public void testIsList() {
+ assertFalse(filter.isList());
+ filter.setList(true);
+ assertTrue(filter.isList());
+ }
+
+ public void testSetList() {
+ filter.setList(false);
+ assertFalse(filter.isList());
+ filter.setList(true);
+ assertTrue(filter.isList());
+ }
+
+}
[12/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceQueryConfigUIFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceQueryConfigUIFactory.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceQueryConfigUIFactory.java
new file mode 100644
index 0000000..3531539
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceQueryConfigUIFactory.java
@@ -0,0 +1,3543 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceQueryConfigUIFactory.java,v $
+ * Revision $Revision: 1.6 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/03/04 16:46:53 $
+ * by $Author: davidwithers $
+ * Created on 21-Jun-2007
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.AbstractButton;
+import javax.swing.AbstractListModel;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.ListModel;
+import javax.swing.SwingConstants;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.DatasetLink;
+import org.biomart.martservice.MartDataset;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartService;
+import org.biomart.martservice.MartServiceException;
+import org.biomart.martservice.config.QueryConfigController;
+import org.biomart.martservice.config.QueryConfigUtils;
+import org.biomart.martservice.config.event.QueryComponentAdapter;
+import org.biomart.martservice.config.event.QueryComponentEvent;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Dataset;
+import org.biomart.martservice.query.Filter;
+import org.biomart.martservice.query.Query;
+import org.biomart.martservice.query.QueryListener;
+import org.ensembl.mart.lib.config.AttributeCollection;
+import org.ensembl.mart.lib.config.AttributeDescription;
+import org.ensembl.mart.lib.config.AttributeGroup;
+import org.ensembl.mart.lib.config.AttributeList;
+import org.ensembl.mart.lib.config.AttributePage;
+import org.ensembl.mart.lib.config.BaseNamedConfigurationObject;
+import org.ensembl.mart.lib.config.DatasetConfig;
+import org.ensembl.mart.lib.config.FilterCollection;
+import org.ensembl.mart.lib.config.FilterDescription;
+import org.ensembl.mart.lib.config.FilterGroup;
+import org.ensembl.mart.lib.config.FilterPage;
+import org.ensembl.mart.lib.config.Option;
+import org.ensembl.mart.lib.config.PushAction;
+
+/**
+ * Implementation of the <code>QueryConfigUIFactory</code> interface that
+ * creates a UI which looks like the Biomart web interface.
+ *
+ * @author David Withers
+ */
+public class MartServiceQueryConfigUIFactory implements QueryConfigUIFactory {
+
+ private static Logger logger = Logger
+ .getLogger(MartServiceQueryConfigUIFactory.class);
+
+ private String version;
+
+ private Color borderColor = new Color(202, 207, 213);
+
+ private Color backgroundColor = Color.WHITE;
+
+ private Color componentBackgroundColor = Color.WHITE;
+
+ private MartService martService;
+
+ private QueryConfigController controller;
+
+ private MartDataset martDataset;
+
+ private DatasetConfig datasetConfig;
+
+ private Map<String, Component> filterNameToComponentMap = new HashMap<String, Component>();
+
+ private Map<String, List<Component>> attributeNameToComponentMap = new HashMap<String, List<Component>>();
+
+ private Map<String, String> filterToDisplayName = new HashMap<String, String>();
+
+ private Map<String, String> attributeToDisplayName = new HashMap<String, String>();
+
+ private Map<String, Component> attributePageNameToComponent = new HashMap<String, Component>();
+
+ private Map<String, JRadioButton> attributePageNameToButton = new HashMap<String, JRadioButton>();
+
+ private boolean settingAttributeState = false;
+
+ private List<Component> componentRegister = new ArrayList<Component>();
+
+ private int datasetNumber;
+
+ public MartServiceQueryConfigUIFactory(MartService martService,
+ QueryConfigController controller, MartDataset martDataset)
+ throws MartServiceException {
+ this(martService, controller, martDataset, 1);
+ }
+
+ public MartServiceQueryConfigUIFactory(MartService martService,
+ QueryConfigController controller, MartDataset martDataset,
+ int datasetNumber) throws MartServiceException {
+ this.martService = martService;
+ this.controller = controller;
+ this.martDataset = martDataset;
+ this.datasetNumber = datasetNumber;
+ version = getConfigStyle();
+ }
+
+ private String getConfigStyle() {
+ String configStyle = "0.5";
+ String version = controller.getMartQuery().getQuery()
+ .getSoftwareVersion();
+ if (version == null || "0.4".equals(version)) {
+ configStyle = "0.4";
+ }
+ return configStyle;
+ }
+
+ /**
+ * Returns the martDataset.
+ *
+ * @return the martDataset.
+ */
+ public MartDataset getMartDataset() {
+ return martDataset;
+ }
+
+ /**
+ * Returns the query configuration for the dataset.
+ *
+ * @return the query configuration for the dataset
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public DatasetConfig getDatasetConfig() throws MartServiceException {
+ if (datasetConfig == null) {
+ datasetConfig = martService.getDatasetConfig(martDataset);
+ }
+ return datasetConfig;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getDatasetConfigUI(org.ensembl.mart.lib.config.DatasetConfig)
+ */
+ public Component getDatasetConfigUI() throws MartServiceException {
+ JPanel panel = new JPanel(new BorderLayout());
+
+ final SummaryPanel summaryPanel = new SummaryPanel();
+
+ final JButton countButton = new JButton("Count");
+ countButton.setFont(countButton.getFont().deriveFont(Font.BOLD));
+ countButton.setOpaque(false);
+ countButton.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ countButton.setEnabled(false);
+ countButton.setText("Counting...");
+ new Thread("BiomartDatasetCount") {
+ public void run() {
+ try {
+ MartQuery martQuery = controller.getMartQuery();
+ Query query = martQuery.getQuery();
+ String datasetName = martQuery.getMartDataset()
+ .getName();
+
+ JLabel label1 = summaryPanel
+ .getDataset1CountLabel();
+ setSummaryCount(query, datasetName, label1);
+
+ Set<String> linkedDatasets = martQuery.getLinkedDatasets();
+ if (linkedDatasets.size() == 1) {
+ String linkedDatasetName = linkedDatasets
+ .iterator().next();
+ JLabel label2 = summaryPanel
+ .getDataset2CountLabel();
+ setSummaryCount(query, linkedDatasetName,
+ label2);
+ }
+
+ } catch (MartServiceException e) {
+ }
+ countButton.setText("Count");
+ countButton.setEnabled(true);
+ }
+ }.start();
+ }
+
+ });
+
+ final JCheckBox uniqueCheckBox = new JCheckBox("Unique results only");
+ uniqueCheckBox.setBackground(Color.BLACK);
+ uniqueCheckBox.setForeground(Color.WHITE);
+ uniqueCheckBox.setSelected(controller.getMartQuery().getQuery()
+ .getUniqueRows() == 1);
+
+ uniqueCheckBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ controller.getMartQuery().getQuery().setUniqueRows(1);
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ controller.getMartQuery().getQuery().setUniqueRows(0);
+ }
+ }
+ });
+
+ JPanel buttonPanel = new JPanel(new BorderLayout());
+ buttonPanel.setBackground(Color.BLACK);
+ buttonPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ buttonPanel.add(countButton, BorderLayout.WEST);
+ buttonPanel.add(uniqueCheckBox, BorderLayout.EAST);
+ panel.add(buttonPanel, BorderLayout.NORTH);
+
+ JLabel label = new JLabel("biomart version 0.6");
+ label.setBackground(Color.BLACK);
+ label.setForeground(Color.WHITE);
+ label.setOpaque(true);
+ label.setBorder(new EmptyBorder(5, 5, 5, 5));
+ panel.add(label, BorderLayout.SOUTH);
+
+ JSplitPane splitPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+ true);
+ splitPanel.setBackground(backgroundColor);
+ splitPanel.setBorder(new EmptyBorder(10, 0, 10, 0));
+ splitPanel.setDividerLocation(250);
+
+ panel.add(splitPanel, BorderLayout.CENTER);
+
+ JScrollPane scrollPane1 = new JScrollPane(summaryPanel);
+ scrollPane1.getVerticalScrollBar().setUnitIncrement(10);
+ scrollPane1.setBorder(new LineBorder(Color.BLACK, 1));
+
+ splitPanel.setLeftComponent(scrollPane1);
+
+ final JComponent inputPanel = createVerticalBox(backgroundColor);
+ inputPanel.setBorder(new EmptyBorder(10, 5, 10, 5));
+
+ JScrollPane scrollPane = new JScrollPane(inputPanel);
+ scrollPane.getVerticalScrollBar().setUnitIncrement(10);
+ scrollPane.setBorder(new LineBorder(Color.BLACK, 1));
+
+ splitPanel.setRightComponent(scrollPane);
+
+ final JComponent datasetPanel = new DatasetPanel();
+ inputPanel.add(datasetPanel);
+
+// final Component linkComponent = new DatasetLinkComponent(inputPanel,
+// summaryPanel);
+// componentRegister.add(linkComponent);
+
+ final JComponent attributePanel = createVerticalBox(backgroundColor);
+ attributePanel.setBorder(new EmptyBorder(10, 5, 10, 5));
+
+ final JComponent filterPanel = createVerticalBox(backgroundColor);
+ filterPanel.setBorder(new EmptyBorder(10, 5, 10, 5));
+
+ summaryPanel.getDataset1Button().addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ inputPanel.removeAll();
+ inputPanel.add(datasetPanel);
+ inputPanel.revalidate();
+ inputPanel.repaint();
+ }
+ });
+
+// summaryPanel.getDataset2Button().addActionListener(
+// new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// inputPanel.removeAll();
+// inputPanel.add(linkComponent);
+// inputPanel.revalidate();
+// inputPanel.repaint();
+// }
+// });
+
+ generateConfiguration(this, summaryPanel, inputPanel, attributePanel,
+ filterPanel);
+
+ summaryPanel.getFilters1Button().addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ inputPanel.removeAll();
+ inputPanel.add(filterPanel);
+ inputPanel.revalidate();
+ inputPanel.repaint();
+ }
+ });
+
+ summaryPanel.getAttributes1Button().addActionListener(
+ new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ inputPanel.removeAll();
+ inputPanel.add(attributePanel);
+ inputPanel.revalidate();
+ inputPanel.repaint();
+ }
+ });
+
+ return panel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributePagesUI(org.ensembl.mart.lib.config.AttributePage[])
+ */
+ public Component getAttributePagesUI(AttributePage[] attributePages,
+ Object data) throws MartServiceException {
+ final JComponent box = createVerticalBox(backgroundColor);
+
+ final JComboBox formatList = new JComboBox();
+ formatList.setBackground(backgroundColor);
+
+ if (datasetNumber == 1) {
+ formatList.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ controller.getMartQuery().getQuery().setFormatter(
+ (String) e.getItem());
+ }
+ }
+ });
+
+ ButtonGroup outputButtons = new ButtonGroup();
+ JRadioButton multipleOutput = new JRadioButton(
+ "Multiple outputs (one per attribute)");
+ multipleOutput.setBackground(backgroundColor);
+ JRadioButton singleOutput = new JRadioButton(
+ "Single output formatted as");
+ singleOutput.setBackground(backgroundColor);
+ outputButtons.add(multipleOutput);
+ outputButtons.add(singleOutput);
+ if (controller.getMartQuery().getQuery().getFormatter() == null) {
+ multipleOutput.setSelected(true);
+ formatList.setEnabled(false);
+ } else {
+ singleOutput.setSelected(true);
+ formatList.setEnabled(true);
+ }
+
+ singleOutput.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ controller.getMartQuery().getQuery().setFormatter(
+ (String) formatList.getSelectedItem());
+ formatList.setEnabled(true);
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ controller.getMartQuery().getQuery().setFormatter(null);
+ formatList.setEnabled(false);
+ }
+ }
+ });
+
+ JPanel multipleOutputBox = new JPanel(new MinimalLayout());
+ multipleOutputBox.setBackground(componentBackgroundColor);
+ multipleOutputBox.add(multipleOutput);
+
+ JComponent formatBox = createHorizontalBox(backgroundColor);
+ formatBox.add(singleOutput);
+ formatBox.add(Box.createHorizontalStrut(10));
+ formatBox.add(formatList);
+ formatBox.add(Box.createHorizontalGlue());
+
+ JComponent outputBox = createVerticalBox(backgroundColor);
+ outputBox.setBorder(new CompoundBorder(new LineBorder(borderColor,
+ 1), new EmptyBorder(10, 10, 10, 10)));
+ outputBox.add(multipleOutputBox);
+ outputBox.add(formatBox);
+
+ box.add(Box.createVerticalStrut(2));
+ box.add(outputBox);
+
+ }
+
+ if (attributePages.length > 1) {
+ ButtonGroup buttonGroup = new ButtonGroup();
+ final Map<String, Component> componentMap = new HashMap<String, Component>();
+ final Map<String, List<String>> formatMap = new HashMap<String, List<String>>();
+
+ final JComponent buttonBox = new JPanel(new GridLayout(0, 2));
+ buttonBox.setBorder(new CompoundBorder(new LineBorder(borderColor,
+ 1), new EmptyBorder(10, 10, 10, 10)));
+ buttonBox.setBackground(backgroundColor);
+ box.add(buttonBox, 0);
+
+ final JComponent pagePanel = new JPanel(new BorderLayout());
+ pagePanel.setBackground(backgroundColor);
+ box.add(pagePanel);
+
+ ItemListener listener = new ItemListener() {
+ Component lastSelectedComponent;
+
+ JRadioButton lastSelectedButton;
+
+ public void itemStateChanged(ItemEvent e) {
+ JRadioButton button = (JRadioButton) e.getItem();
+ if (button != null) {
+ Component selectedComponent = componentMap.get(button
+ .getActionCommand());
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ boolean switchPage = true;
+ if (lastSelectedComponent != null) {
+ Map<String, AttributeComponent> selected = new HashMap<String, AttributeComponent>();
+ // find all attributes on the last page that
+ // were selected
+ List<AttributeComponent> oldChildren = getAttributeComponents(lastSelectedComponent);
+ for (AttributeComponent attributeComponent : oldChildren) {
+ if (attributeComponent.isSelected()) {
+ selected.put(attributeComponent
+ .getQualifiedName(),
+ attributeComponent);
+ }
+ }
+ // remove attributes that are already selected
+ // on
+ // the new page
+ List<AttributeComponent> newChildren = getAttributeComponents(selectedComponent);
+ for (AttributeComponent attributeComponent : newChildren) {
+ if (attributeComponent.isSelected()) {
+ selected.remove(attributeComponent
+ .getQualifiedName());
+ }
+ }
+ Collection<AttributeComponent> stillSelected = selected
+ .values();
+ if (stillSelected.size() > 0) {
+ List<String> attributeNames = new ArrayList<String>();
+ for (AttributeComponent component : stillSelected) {
+ attributeNames.add(component
+ .getButton().getText());
+ }
+ List<Object> message = new ArrayList<Object>();
+ message
+ .add("The "
+ + button.getText()
+ + " page does not contain the following attributes:");
+ JList jList = new JList(attributeNames
+ .toArray());
+ jList.setBorder(LineBorder
+ .createGrayLineBorder());
+ message.add(jList);
+ message
+ .add("These attributes will be removed. Do you wish to continue?");
+ switchPage = JOptionPane.showConfirmDialog(
+ buttonBox, message.toArray(),
+ "Confirm page change",
+ JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
+ }
+ if (switchPage) {
+ // deselect any attributes on the old page
+ // that are not on the new page
+ for (AttributeComponent attributeComponent : stillSelected) {
+ attributeComponent.setSelected(false);
+ }
+ }
+ }
+ if (switchPage) {
+ pagePanel.add(selectedComponent,
+ BorderLayout.NORTH);
+ if (datasetNumber == 1) {
+ List<String> formats = formatMap.get(button
+ .getActionCommand());
+ formatList
+ .setModel(new DefaultComboBoxModel(
+ formats.toArray()));
+ String formatter = controller
+ .getMartQuery().getQuery()
+ .getFormatter();
+ if (formatter != null) {
+ formatList.getModel().setSelectedItem(
+ null);
+ if (formats.contains(formatter)) {
+ formatList.getModel()
+ .setSelectedItem(formatter);
+ } else if (formats.size() > 0) {
+ formatList.getModel()
+ .setSelectedItem(
+ formats.get(0));
+ }
+ }
+ }
+ } else {
+ lastSelectedButton.setSelected(true);
+ }
+ box.revalidate();
+ box.repaint();
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ pagePanel.removeAll();
+ lastSelectedComponent = selectedComponent;
+ lastSelectedButton = button;
+ }
+ }
+ }
+
+ };
+
+ for (int i = 0; i < attributePages.length; i++) {
+ if (QueryConfigUtils.display(attributePages[i])) {
+ Component component = getAttributePageUI(attributePages[i],
+ data);
+ JRadioButton button = new JRadioButton(attributePages[i]
+ .getDisplayName());
+ String description = attributePages[i].getDescription();
+ if (description != null) {
+ button.setToolTipText(description);
+ }
+ button.setBackground(backgroundColor);
+ button.setFont(button.getFont().deriveFont(Font.BOLD));
+ button
+ .setActionCommand(attributePages[i]
+ .getInternalName());
+ button.addItemListener(listener);
+ buttonGroup.add(button);
+ buttonBox.add(button);
+ componentMap.put(attributePages[i].getInternalName(),
+ component);
+ formatMap.put(attributePages[i].getInternalName(), getFormatList(attributePages[i]));
+ attributePageNameToComponent.put(attributePages[i]
+ .getInternalName(), component);
+ attributePageNameToButton.put(attributePages[i]
+ .getInternalName(), button);
+ }
+ }
+
+ } else if (attributePages.length == 1) {
+ if (datasetNumber == 1) {
+ List<String> formats = Arrays.asList(attributePages[0]
+ .getOutFormats().toUpperCase().split(","));
+ formatList
+ .setModel(new DefaultComboBoxModel(formats.toArray()));
+ String formatter = controller.getMartQuery().getQuery()
+ .getFormatter();
+ if (formatter != null) {
+ formatList.getModel().setSelectedItem(null);
+ if (formats.contains(formatter)) {
+ formatList.getModel().setSelectedItem(formatter);
+ } else if (formats.size() > 0) {
+ formatList.getModel().setSelectedItem(formats.get(0));
+ }
+ }
+ }
+ box.add(getAttributePageUI(attributePages[0], data));
+
+ } else {
+ box.add(new JLabel("No attributes available"));
+ }
+
+ JPanel northPanel = new JPanel(new BorderLayout());
+ northPanel.setBackground(backgroundColor);
+ northPanel.add(box, BorderLayout.NORTH);
+
+ return northPanel;
+
+ // return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributePageUI(org.ensembl.mart.lib.config.AttributePage)
+ */
+ public Component getAttributePageUI(AttributePage attributePage, Object data)
+ throws MartServiceException {
+ JComponent box = createVerticalBox(backgroundColor);
+
+ AttributeGroup[] attributeGroups = (AttributeGroup[]) attributePage
+ .getAttributeGroups().toArray(new AttributeGroup[0]);
+
+ box.add(getAttributeGroupsUI(attributeGroups, data));
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeGroupsUI(org.ensembl.mart.lib.config.AttributeGroup[])
+ */
+ public Component getAttributeGroupsUI(AttributeGroup[] attributeGroups,
+ Object data) throws MartServiceException {
+ JComponent box = createVerticalBox(backgroundColor);
+
+ for (int i = 0; i < attributeGroups.length; i++) {
+ if (QueryConfigUtils.display(attributeGroups[i])) {
+ box.add(Box.createVerticalStrut(2));
+ box.add(getAttributeGroupUI(attributeGroups[i], data));
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeGroupUI(org.ensembl.mart.lib.config.AttributeGroup)
+ */
+ public Component getAttributeGroupUI(AttributeGroup attributeGroup,
+ Object data) throws MartServiceException {
+ JLabel title = new JLabel(attributeGroup.getDisplayName());
+ title.setFont(title.getFont().deriveFont(Font.PLAIN));
+
+ String description = attributeGroup.getDescription();
+ if (description != null) {
+ title.setToolTipText(description);
+ }
+ ExpandableBox box = new ExpandableBox(title, componentBackgroundColor,
+ borderColor, new Insets(10, 10, 10, 10));
+
+ AttributeCollection[] attributeCollections = attributeGroup
+ .getAttributeCollections();
+ box.add(getAttributeCollectionsUI(attributeCollections, data));
+
+ box.setExpanded(false);
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeCollectionsUI(org.ensembl.mart.lib.config.AttributeCollection[])
+ */
+ public Component getAttributeCollectionsUI(
+ AttributeCollection[] attributeCollections, Object data)
+ throws MartServiceException {
+ JComponent box = createVerticalBox(componentBackgroundColor);
+
+ for (int i = 0; i < attributeCollections.length; i++) {
+ if (QueryConfigUtils.display(attributeCollections[i])) {
+ box.add(Box.createVerticalStrut(10));
+ box
+ .add(getAttributeCollectionUI(attributeCollections[i],
+ data));
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeCollectionUI(org.ensembl.mart.lib.config.AttributeCollection)
+ */
+ public Component getAttributeCollectionUI(
+ AttributeCollection attributeCollection, Object data)
+ throws MartServiceException {
+ JComponent box = null;
+
+ AttributeDescription[] attributeDescriptions = (AttributeDescription[]) attributeCollection
+ .getAttributeDescriptions()
+ .toArray(new AttributeDescription[0]);
+
+ AttributeList[] attributeLists = (AttributeList[]) attributeCollection
+ .getAttributeLists().toArray(new AttributeList[0]);
+
+ JLabel sequenceLabel = null;
+ if ("seq_scope_type".equals(attributeCollection.getInternalName())) {
+ sequenceLabel = new JLabel(MartServiceIcons
+ .getIcon("gene_schematic"));
+ box = createBox(sequenceLabel, false);
+ } else if (attributeDescriptions.length > 1
+ || attributeLists.length > 1) {
+ // more than one attribute so create a box with the collection name
+ // as a header
+ JLabel title = new JLabel(attributeCollection.getDisplayName());
+ title.setFont(title.getFont().deriveFont(Font.BOLD));
+ String description = attributeCollection.getDescription();
+ if (description != null) {
+ title.setToolTipText(description);
+ }
+ box = createBox(title, false);
+ } else {
+ box = createBox(null, false);
+ }
+
+ int maxSelect = attributeCollection.getMaxSelect();
+ if (maxSelect == 1) {
+ if (attributeDescriptions.length > 0) {
+ box.add(getAttributeDescriptionsUI(attributeDescriptions,
+ new Object[] { SINGLE_SELECTION, sequenceLabel }));
+ } else {
+ box.add(getAttributeListsUI(attributeLists, new Object[] {
+ SINGLE_SELECTION, sequenceLabel }));
+ }
+ } else {
+ if (attributeDescriptions.length > 0) {
+ box.add(getAttributeDescriptionsUI(attributeDescriptions,
+ new Object[] { MULTIPLE_SELECTION, sequenceLabel }));
+ } else {
+ box.add(getAttributeListsUI(attributeLists, new Object[] {
+ MULTIPLE_SELECTION, sequenceLabel }));
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeDescriptionsUI(org.ensembl.mart.lib.config.AttributeDescription[],
+ * int)
+ */
+ public Component getAttributeDescriptionsUI(
+ AttributeDescription[] attributeDescriptions, Object data)
+ throws MartServiceException {
+ Object[] dataArray = (Object[]) data;
+ JComponent box = new JPanel(new GridLayout(1, 2));
+ box.setBackground(componentBackgroundColor);
+ JComponent box1 = createVerticalBox(componentBackgroundColor);
+ JComponent box2 = createVerticalBox(componentBackgroundColor);
+ box.add(box1);
+ box.add(box2);
+
+ // button group used if the attribute collection is SINGLE_SELECTION
+ ButtonGroup buttonGroup = new ButtonGroup();
+ JRadioButton off = new JRadioButton("OFF");
+ buttonGroup.add(off);
+
+ JComponent currentBox = box1;
+
+ for (int i = 0; i < attributeDescriptions.length; i++) {
+ if (QueryConfigUtils.display(attributeDescriptions[i])) {
+ Component component = getAttributeDescriptionUI(
+ attributeDescriptions[i],
+ dataArray[0] == SINGLE_SELECTION ? new Object[] { off,
+ dataArray[1] } : new Object[] { null,
+ dataArray[1] });
+ if (component != null) {
+ currentBox.add(component);
+ if (dataArray[0] == SINGLE_SELECTION
+ && component instanceof AttributeComponent) {
+ AttributeComponent attributeComponent = (AttributeComponent) component;
+ buttonGroup.add(attributeComponent.getButton());
+ }
+ if (QueryConfigUtils.isFilterReference(
+ attributeDescriptions[i], version)) {
+ FilterDescription filterDescription = QueryConfigUtils
+ .getReferencedFilterDescription(
+ attributeDescriptions[i], version);
+ Component filterComponent = getFilterDescriptionUI(
+ filterDescription, data);
+ if (filterComponent instanceof QueryComponent
+ && component instanceof AttributeComponent) {
+ AttributeComponent attributeComponent = (AttributeComponent) component;
+ ((QueryComponent) filterComponent)
+ .setSelectorButton(attributeComponent
+ .getButton());
+ }
+ componentRegister.add(filterComponent);
+ box2.add(filterComponent);
+ currentBox = box2;
+ }
+ if (currentBox == box1) {
+ currentBox = box2;
+ } else {
+ currentBox = box1;
+ }
+ }
+ }
+ }
+ currentBox.add(Box.createVerticalGlue());
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeDescriptionUI(org.ensembl.mart.lib.config.AttributeDescription,
+ * int)
+ */
+ public Component getAttributeDescriptionUI(
+ AttributeDescription attributeDescription, Object data)
+ throws MartServiceException {
+ Object[] dataArray = (Object[]) data;
+ MartDataset dataset = martDataset;
+ AttributeDescription displayedAttribute;
+ if (QueryConfigUtils.isReference(attributeDescription, version)) {
+ dataset = QueryConfigUtils.getReferencedDataset(martService,
+ martDataset, attributeDescription, version);
+ if (dataset == null) {
+ return null;
+ }
+ if (QueryConfigUtils.isFilterReference(attributeDescription,
+ version)) {
+ FilterDescription filter = QueryConfigUtils
+ .getReferencedFilterDescription(martService, dataset,
+ attributeDescription, version);
+ if (filter == null) {
+ return null;
+ }
+ displayedAttribute = attributeDescription;
+ displayedAttribute.setDisplayName(filter.getDisplayName());
+ filterToDisplayName.put(filter.getInternalName(), filter
+ .getDisplayName());
+ } else {
+ displayedAttribute = QueryConfigUtils
+ .getReferencedAttributeDescription(martService,
+ dataset, attributeDescription, version);
+ if (displayedAttribute == null) {
+ // if the reference can't be resolved the the attribute just
+ // doesn't get displayed
+ return null;
+ }
+ }
+ } else {
+ displayedAttribute = attributeDescription;
+ }
+
+ final AttributeComponent component = new AttributeComponent(
+ displayedAttribute, martDataset, dataArray[0]);
+ component.setPointerDataset(attributeDescription
+ .getAttribute("pointerDataset"));
+ if (!QueryConfigUtils.isFilterReference(attributeDescription, version)) {
+ if (!attributeNameToComponentMap.containsKey(component
+ .getQualifiedName())) {
+ attributeNameToComponentMap.put(component.getQualifiedName(),
+ new ArrayList<Component>());
+ }
+ attributeNameToComponentMap.get(component
+ .getQualifiedName()).add(component);
+ componentRegister.add(component);
+ // nasty hard coded rules that aren't in the configs
+ // component.addQueryComponentListener(new QueryComponentAdapter() {
+ // public void attributeAdded(QueryComponentEvent event) {
+ // String name = component.getName();
+ // String dataset = component.getDataset().getName();
+ // if (name.equals("coding_gene_flank")
+ // || name.equals("coding_transcript_flank")
+ // || name.equals("transcript_flank")
+ // || name.equals("gene_flank")) {
+ // QueryComponent filterComponent = (QueryComponent)
+ // filterNameToComponentMap
+ // .get("upstream_flank");
+ // if (filterComponent != null) {
+ // filterComponent.setSelected(true);
+ // }
+ // filterComponent = (QueryComponent) filterNameToComponentMap
+ // .get("downstream_flank");
+ // if (filterComponent != null) {
+ // filterComponent.setSelected(true);
+ // }
+ // }
+ // }
+ //
+ // });
+ }
+ if (dataArray[1] instanceof JLabel) {
+ final JLabel sequenceLabel = (JLabel) dataArray[1];
+ component.addQueryComponentListener(new QueryComponentAdapter() {
+ public void attributeAdded(QueryComponentEvent event) {
+ String name = component.getName();
+ if ("3utr".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_3utr"));
+ } else if ("5utr".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_5utr"));
+ } else if ("cdna".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_cdna"));
+ } else if ("coding_gene_flank".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_coding_gene_flank"));
+ } else if ("coding_transcript_flank".equals(name)) {
+ sequenceLabel
+ .setIcon(MartServiceIcons
+ .getIcon("gene_schematic_coding_transcript_flank"));
+ } else if ("coding".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_coding"));
+ } else if ("gene_exon_intron".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_gene_exon_intron"));
+ } else if ("gene_exon".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_gene_exon"));
+ } else if ("gene_flank".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_gene_flank"));
+ } else if ("peptide".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_peptide"));
+ } else if ("transcript_exon_intron".equals(name)) {
+ sequenceLabel
+ .setIcon(MartServiceIcons
+ .getIcon("gene_schematic_transcript_exon_intron"));
+ } else if ("transcript_exon".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_transcript_exon"));
+ } else if ("transcript_flank".equals(name)) {
+ sequenceLabel.setIcon(MartServiceIcons
+ .getIcon("gene_schematic_transcript_flank"));
+ }
+ }
+
+ });
+ }
+ return component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeListsUI(org.ensembl.mart.lib.config.AttributeList[],
+ * int)
+ */
+ public Component getAttributeListsUI(AttributeList[] attributeLists,
+ Object data) throws MartServiceException {
+ Object[] dataArray = (Object[]) data;
+ JComponent box = new JPanel(new GridLayout(1, 2));
+ box.setBackground(componentBackgroundColor);
+ JComponent box1 = createVerticalBox(componentBackgroundColor);
+ JComponent box2 = createVerticalBox(componentBackgroundColor);
+ box.add(box1);
+ box.add(box2);
+
+ // button group used if the attribute collection is SINGLE_SELECTION
+ ButtonGroup buttonGroup = new ButtonGroup();
+ JRadioButton off = new JRadioButton("OFF");
+ buttonGroup.add(off);
+
+ JComponent currentBox = box1;
+
+ for (int i = 0; i < attributeLists.length; i++) {
+ if (QueryConfigUtils.display(attributeLists[i])) {
+ Component component = getAttributeListUI(attributeLists[i],
+ dataArray[0] == SINGLE_SELECTION ? new Object[] { off,
+ dataArray[1] } : new Object[] { null,
+ dataArray[1] });
+ if (component != null) {
+ currentBox.add(component);
+ if (dataArray[0] == SINGLE_SELECTION
+ && component instanceof AttributeComponent) {
+ AttributeComponent attributeComponent = (AttributeComponent) component;
+ buttonGroup.add(attributeComponent.getButton());
+ }
+ if (currentBox == box1) {
+ currentBox = box2;
+ } else {
+ currentBox = box1;
+ }
+ }
+ }
+ }
+ currentBox.add(Box.createVerticalGlue());
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getAttributeListUI(org.ensembl.mart.lib.config.AttributeList,
+ * int)
+ */
+ public Component getAttributeListUI(AttributeList attributeList, Object data)
+ throws MartServiceException {
+ Object[] dataArray = (Object[]) data;
+
+ AttributeComponent component = new AttributeComponent(attributeList,
+ martDataset, dataArray[0]);
+
+ if (!attributeNameToComponentMap.containsKey(component
+ .getQualifiedName())) {
+ attributeNameToComponentMap.put(component.getQualifiedName(),
+ new ArrayList<Component>());
+ }
+ attributeNameToComponentMap.get(component.getQualifiedName())
+ .add(component);
+ componentRegister.add(component);
+ /*
+ * if (dataArray[1] instanceof JLabel) { final JLabel sequenceLabel =
+ * (JLabel) dataArray[1]; component.addQueryComponentListener(new
+ * QueryComponentAdapter() { public void
+ * attributeAdded(QueryComponentEvent event) { String name =
+ * component.getName(); if ("3utr".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_3utr")); } else if ("5utr".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_5utr")); } else if ("cdna".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_cdna")); } else if
+ * ("coding_gene_flank".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_coding_gene_flank")); } else if
+ * ("coding_transcript_flank".equals(name)) { sequenceLabel
+ * .setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_coding_transcript_flank")); } else if
+ * ("coding".equals(name)) { sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_coding")); } else if
+ * ("gene_exon_intron".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_gene_exon_intron")); } else if
+ * ("gene_exon".equals(name)) { sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_gene_exon")); } else if
+ * ("gene_flank".equals(name)) { sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_gene_flank")); } else if
+ * ("peptide".equals(name)) { sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_peptide")); } else if
+ * ("transcript_exon_intron".equals(name)) { sequenceLabel
+ * .setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_transcript_exon_intron")); } else if
+ * ("transcript_exon".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_transcript_exon")); } else if
+ * ("transcript_flank".equals(name)) {
+ * sequenceLabel.setIcon(MartServiceIcons
+ * .getIcon("gene_schematic_transcript_flank")); } }
+ *
+ * }); }
+ */
+ return component;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterPagesUI(org.ensembl.mart.lib.config.FilterPage[])
+ */
+ public Component getFilterPagesUI(FilterPage[] filterPages, Object data)
+ throws MartServiceException {
+ final JComponent box = createVerticalBox(backgroundColor);
+
+ for (int i = 0; i < filterPages.length; i++) {
+ if (QueryConfigUtils.display(filterPages[i])) {
+ box.add(getFilterPageUI(filterPages[i], data));
+ }
+ }
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.setBackground(backgroundColor);
+ panel.add(box, BorderLayout.NORTH);
+
+ return panel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterPageUI(org.ensembl.mart.lib.config.FilterPage)
+ */
+ public Component getFilterPageUI(FilterPage filterPage, Object data)
+ throws MartServiceException {
+ JComponent box = createVerticalBox(backgroundColor);
+
+ FilterGroup[] filterGroups = (FilterGroup[]) filterPage
+ .getFilterGroups().toArray(new FilterGroup[0]);
+ box.add(getFilterGroupsUI(filterGroups, data));
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterGroupsUI(org.ensembl.mart.lib.config.FilterGroup[])
+ */
+ public Component getFilterGroupsUI(FilterGroup[] filterGroups, Object data)
+ throws MartServiceException {
+ JComponent box = createVerticalBox(backgroundColor);
+
+ for (int i = 0; i < filterGroups.length; i++) {
+ if (QueryConfigUtils.display(filterGroups[i])) {
+ box.add(Box.createVerticalStrut(2));
+ box.add(getFilterGroupUI(filterGroups[i], data));
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterGroupUI(org.ensembl.mart.lib.config.FilterGroup)
+ */
+ public Component getFilterGroupUI(FilterGroup filterGroup, Object data)
+ throws MartServiceException {
+ JLabel title = new JLabel(filterGroup.getDisplayName());
+ title.setFont(title.getFont().deriveFont(Font.PLAIN));
+ String description = filterGroup.getDescription();
+ if (description != null) {
+ title.setToolTipText(description);
+ }
+ ExpandableBox box = new ExpandableBox(title, componentBackgroundColor,
+ borderColor, new Insets(10, 10, 10, 10));
+
+ FilterCollection[] filterCollections = filterGroup
+ .getFilterCollections();
+ box.add(getFilterCollectionsUI(filterCollections, data));
+
+ box.setExpanded(false);
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterCollectionsUI(org.ensembl.mart.lib.config.FilterCollection[])
+ */
+ public Component getFilterCollectionsUI(
+ FilterCollection[] filterCollections, Object data)
+ throws MartServiceException {
+ JComponent box = createVerticalBox(componentBackgroundColor);
+
+ for (int i = 0; i < filterCollections.length; i++) {
+ if (QueryConfigUtils.display(filterCollections[i])) {
+ Component component = getFilterCollectionUI(
+ filterCollections[i], data);
+ if (component != null) {
+ box.add(Box.createVerticalStrut(10));
+ box.add(component);
+ }
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterCollectionUI(org.ensembl.mart.lib.config.FilterCollection)
+ */
+ public Component getFilterCollectionUI(FilterCollection filterCollection,
+ Object data) throws MartServiceException {
+ JComponent box = null;
+
+ String displayName = filterCollection.getDisplayName();
+ if (displayName == null) {
+ displayName = filterCollection.getInternalName();
+ }
+ AbstractButton selectorButton = new JCheckBox(QueryConfigUtils
+ .splitSentence(displayName));
+ selectorButton.setFont(selectorButton.getFont().deriveFont(Font.PLAIN));
+ selectorButton.setBackground(componentBackgroundColor);
+ String description = filterCollection.getDescription();
+ if (description != null) {
+ selectorButton.setToolTipText(description);
+ }
+
+ FilterDescription[] filterDescriptions = (FilterDescription[]) filterCollection
+ .getFilterDescriptions().toArray(new FilterDescription[0]);
+
+ if (filterDescriptions.length == 1) {
+ if (QueryConfigUtils.display(filterDescriptions[0])) {
+ Component filterComponent = getFilterDescriptionUI(
+ filterDescriptions[0], data);
+ if (filterComponent != null) {
+ filterToDisplayName.put(
+ filterDescriptions[0].getInternalName(), displayName);
+ if (QueryConfigUtils
+ .isReference(filterDescriptions[0], version)) {
+ MartDataset dataset = QueryConfigUtils
+ .getReferencedDataset(martService, martDataset,
+ filterDescriptions[0], version);
+ FilterDescription referencedFilter = QueryConfigUtils
+ .getReferencedFilterDescription(martService,
+ dataset, filterDescriptions[0], version);
+ filterToDisplayName.put(referencedFilter.getInternalName(),
+ displayName);
+ }
+
+ box = createBox(null, false);
+ JComponent grid = new JPanel(new GridLayout(1, 2));
+ grid.setBackground(componentBackgroundColor);
+ JPanel buttonPanel = new JPanel(new MinimalLayout());
+ buttonPanel.setBackground(componentBackgroundColor);
+ buttonPanel.add(selectorButton);
+ grid.add(buttonPanel);
+ if (filterComponent instanceof QueryComponent) {
+ ((QueryComponent) filterComponent)
+ .setSelectorButton(selectorButton);
+ }
+ grid.add(filterComponent);
+ box.add(grid);
+ }
+ }
+ } else {
+ Component component = getFilterDescriptionsUI(filterDescriptions,
+ selectorButton);
+ if (component != null) {
+ box = createBox(selectorButton, false);
+ box.add(component);
+ }
+ }
+
+ return box;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterDescriptionsUI(org.ensembl.mart.lib.config.FilterDescription[],
+ * int)
+ */
+ public Component getFilterDescriptionsUI(
+ FilterDescription[] filterDescriptions, Object data)
+ throws MartServiceException {
+ List<Component> components = new ArrayList<Component>();
+ for (int i = 0; i < filterDescriptions.length; i++) {
+ if (QueryConfigUtils.display(filterDescriptions[i])) {
+ Component component = getFilterDescriptionUI(
+ filterDescriptions[i], data);
+ if (component != null) {
+ if (component instanceof QueryComponent
+ && data instanceof AbstractButton) {
+ ((QueryComponent) component)
+ .setSelectorButton((AbstractButton) data);
+ }
+
+ String displayName = filterDescriptions[i].getDisplayName();
+ if (displayName == null) {
+ logger.info("Cant find a display name for filter '"
+ + filterDescriptions[i].getInternalName() + "'");
+ displayName = filterDescriptions[i].getInternalName();
+ }
+ filterToDisplayName.put(
+ filterDescriptions[i].getInternalName(), displayName);
+ JLabel displayLabel = new JLabel(QueryConfigUtils
+ .splitSentence(displayName));
+ displayLabel.setFont(displayLabel.getFont().deriveFont(
+ Font.PLAIN));
+ String description = filterDescriptions[i].getDescription();
+ if (description != null) {
+ displayLabel.setToolTipText(description);
+ }
+ displayLabel.setBackground(componentBackgroundColor);
+ displayLabel.setBorder(new EmptyBorder(0, 22, 0, 0));
+
+ components.add(displayLabel);
+ components.add(component);
+ }
+ }
+ }
+
+ if (components.size() > 0) {
+ JComponent box = new JPanel(
+ new GridLayout(components.size() / 2, 2));
+ box.setBackground(componentBackgroundColor);
+ for (Component component : components) {
+ box.add(component);
+ }
+ return box;
+ } else {
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryConfigUIFactory#getFilterDescriptionUI(org.ensembl.mart.lib.config.FilterDescription,
+ * int)
+ */
+ public Component getFilterDescriptionUI(
+ FilterDescription filterDescription, Object data)
+ throws MartServiceException {
+ QueryComponent component;
+
+ String pointerDataset = filterDescription
+ .getAttribute("pointerDataset");
+ MartDataset dataset = martDataset;
+ FilterDescription displayedFilter;
+ if (QueryConfigUtils.isReference(filterDescription, version)) {
+ dataset = QueryConfigUtils.getReferencedDataset(martService,
+ martDataset, filterDescription, version);
+ if (dataset == null) {
+ return null;
+ }
+ displayedFilter = QueryConfigUtils.getReferencedFilterDescription(
+ martService, dataset, filterDescription, version);
+ if (displayedFilter == null){
+ return null;
+ }
+ filterDescription.setDisplayName(displayedFilter.getDisplayName());
+ } else {
+ displayedFilter = filterDescription;
+ }
+ assert dataset != null;
+
+ String type = displayedFilter.getType();
+ if (type == null) {
+ type = "text";// default filter type
+ }
+
+ if (type.equals("boolean") || type.equals("boolean_num")) {
+ component = new BooleanFilterComponent(displayedFilter, martDataset);
+ component.setPointerDataset(pointerDataset);
+ componentRegister.add(component);
+ } else if (type.endsWith("list") || type.endsWith("basic_filter")
+ || QueryConfigUtils.isList(displayedFilter)) {
+ if (type.equals("boolean_list")
+ || QueryConfigUtils.isBooleanList(displayedFilter)) {
+ Option[] options = displayedFilter.getOptions();
+ List filters = new ArrayList();
+ for (int i = 0; i < options.length; i++) {
+ FilterDescription booleanFilterDescription = new FilterDescription(
+ options[i]);
+ QueryComponent queryComponent = new BooleanFilterComponent(
+ booleanFilterDescription, martDataset);
+ queryComponent.setPointerDataset(pointerDataset);
+ filters.add(queryComponent);
+ componentRegister.add(queryComponent);
+ }
+ component = new BooleanListFilterComponent(displayedFilter,
+ martDataset, filters);
+ component.setPointerDataset(pointerDataset);
+ } else if (type.equals("id_list")
+ || QueryConfigUtils.isIdList(displayedFilter)) {
+ Option[] options = displayedFilter.getOptions();
+ List<TextFilterComponent> filters = new ArrayList<TextFilterComponent>();
+ for (int i = 0; i < options.length; i++) {
+ FilterDescription idFilterDescription = new FilterDescription(
+ options[i]);
+ idFilterDescription.setType("id_list");
+ TextFilterComponent queryComponent = new TextFilterComponent(
+ idFilterDescription, martDataset);
+ queryComponent.setPointerDataset(pointerDataset);
+ filters.add(queryComponent);
+ componentRegister.add(queryComponent);
+ }
+ component = new IdListFilterComponent(displayedFilter,
+ martDataset, filters);
+ component.setPointerDataset(pointerDataset);
+ } else if (QueryConfigUtils.isNestedList(displayedFilter)) {
+ TextFilterComponent filterComponent = new TextFilterComponent(
+ displayedFilter, martDataset);
+ filterComponent.setPointerDataset(pointerDataset);
+ filterComponent.add(QueryConfigUtils.getOptionButton(
+ displayedFilter, filterComponent));
+ component = filterComponent;
+ componentRegister.add(component);
+ } else {
+ ListFilterComponent filterComponent = new ListFilterComponent(
+ getDatasetConfig().getDataset(), displayedFilter,
+ martDataset, filterNameToComponentMap);
+ filterComponent.setPointerDataset(pointerDataset);
+ // map the component to a local dataset name as the 'ref' of a
+ // pushaction may be a local reference
+ filterNameToComponentMap.put(getDatasetConfig().getDataset()
+ + "." + displayedFilter.getInternalName(),
+ filterComponent);
+ // if the filter is a reference then also map the component to
+ // its referenced dataset name as the 'ref' of a pushaction may
+ // be a non-local reference
+ if (QueryConfigUtils.isReference(filterDescription, version)) {
+ filterNameToComponentMap.put(filterDescription
+ .getInternalName(), filterComponent);
+ }
+ component = filterComponent;
+ componentRegister.add(component);
+ }
+ } else {
+ String multipleValues = displayedFilter.getMultipleValues();
+ if ("1".equals(multipleValues)) {
+ component = new MultipleTextFilterComponent(displayedFilter, martDataset);
+ } else {
+ component = new TextFilterComponent(displayedFilter, martDataset);
+ }
+ component.setPointerDataset(pointerDataset);
+ componentRegister.add(component);
+ // mapping for hard coded rules
+ filterNameToComponentMap.put(filterDescription.getInternalName(),
+ component);
+ }
+
+ return component;
+ }
+
+ private void registerComponents() {
+ for (Iterator iter = componentRegister.iterator(); iter.hasNext();) {
+ QueryComponent component = (QueryComponent) iter.next();
+ controller.register(component);
+ }
+ }
+
+ private void deregisterComponents() {
+ for (Iterator iter = componentRegister.iterator(); iter.hasNext();) {
+ QueryComponent component = (QueryComponent) iter.next();
+ controller.deregister(component);
+ }
+ }
+
+ /**
+ *
+ * @param inputPanel
+ * @param attributePanel
+ * @param filterPanel
+ */
+ private void generateConfiguration(
+ final MartServiceQueryConfigUIFactory factory,
+ final SummaryPanel summaryPanel, final JComponent inputPanel,
+ final JComponent attributePanel, final JComponent filterPanel) {
+ final JProgressBar filterProgressBar = new JProgressBar();
+ filterProgressBar.setIndeterminate(true);
+ filterProgressBar.setStringPainted(true);
+ filterProgressBar.setString("Fetching filter configuration");
+ filterPanel.add(filterProgressBar);
+
+ final JProgressBar attributeProgressBar = new JProgressBar();
+ attributeProgressBar.setIndeterminate(true);
+ attributeProgressBar.setStringPainted(true);
+ attributeProgressBar.setString("Fetching attribute configuration");
+ attributePanel.add(attributeProgressBar);
+
+ new Thread("DatasetConfigUI") {
+ public void run() {
+ try {
+
+ FilterPage[] filterPages = factory.getDatasetConfig()
+ .getFilterPages();
+ AttributePage[] attributePages = factory.getDatasetConfig()
+ .getAttributePages();
+
+ final Component filterPagesComponent = factory
+ .getFilterPagesUI(filterPages, null);
+ final Component attributePagesComponent = factory
+ .getAttributePagesUI(attributePages, null);
+
+ filterPanel.remove(filterProgressBar);
+ filterPanel.add(filterPagesComponent);
+
+ attributePanel.remove(attributeProgressBar);
+ attributePanel.add(attributePagesComponent);
+
+ factory.registerComponents();
+
+ factory.selectAttributePage(attributePages);
+
+ } catch (MartServiceException e) {
+ logger.error("Error while fetching dataset configuration", e);
+ JTextArea textArea = new JTextArea();
+ textArea
+ .append("Error while fetching dataset configuration\n\n");
+ textArea.append(e.getMessage());
+ inputPanel.removeAll();
+ inputPanel.add(textArea);
+ } catch (Exception e) {
+ logger.error("Error while generating the Query Editor", e);
+ JTextArea textArea = new JTextArea();
+ textArea
+ .append("Error while generating the Query Editor\n\n");
+ textArea.append(e.toString());
+ inputPanel.removeAll();
+ inputPanel.add(textArea);
+ } finally {
+ inputPanel.revalidate();
+ inputPanel.repaint();
+ summaryPanel.updateDatasets();
+ }
+ }
+ }.start();
+ }
+
+ private List<AttributeComponent> getAttributeComponents(Component component) {
+ List<AttributeComponent> attributeComponents = new ArrayList<AttributeComponent>();
+ if (component instanceof AttributeComponent) {
+ attributeComponents.add((AttributeComponent) component);
+ } else if (component instanceof ExpandableBox) {
+ Component[] children = ((ExpandableBox) component).getComponents();
+ for (int i = 0; i < children.length; i++) {
+ attributeComponents.addAll(getAttributeComponents(children[i]));
+ }
+ } else if (component instanceof Container) {
+ Component[] children = ((Container) component).getComponents();
+ for (int i = 0; i < children.length; i++) {
+ attributeComponents.addAll(getAttributeComponents(children[i]));
+ }
+ }
+ return attributeComponents;
+ }
+
+ private List<AttributeComponent> getSelectedAttributeComponents(
+ Component component) {
+ List<AttributeComponent> attributeComponents = new ArrayList<AttributeComponent>();
+ if (component instanceof AttributeComponent) {
+ if (((AttributeComponent) component).isSelected()) {
+ attributeComponents.add((AttributeComponent) component);
+ }
+ } else if (component instanceof ExpandableBox) {
+ Component[] children = ((ExpandableBox) component).getComponents();
+ for (int i = 0; i < children.length; i++) {
+ attributeComponents
+ .addAll(getSelectedAttributeComponents(children[i]));
+ }
+ } else if (component instanceof Container) {
+ Component[] children = ((Container) component).getComponents();
+ for (int i = 0; i < children.length; i++) {
+ attributeComponents
+ .addAll(getSelectedAttributeComponents(children[i]));
+ }
+ }
+ return attributeComponents;
+ }
+
+ private void selectAttributePage(AttributePage[] attributePages) {
+ int selectedAttributes = -1;
+ JRadioButton selectedButton = null;
+ Component selectedComponent = null;
+
+ for (int i = 0; i < attributePages.length; i++) {
+ if (QueryConfigUtils.display(attributePages[i])) {
+ Component component = attributePageNameToComponent
+ .get(attributePages[i].getInternalName());
+ JRadioButton button = attributePageNameToButton
+ .get(attributePages[i].getInternalName());
+ if (component != null && button != null) {
+ int attributeCount = getSelectedAttributeComponents(
+ component).size();
+ if (attributeCount > selectedAttributes) {
+ selectedAttributes = attributeCount;
+ selectedButton = button;
+ selectedComponent = component;
+ }
+ }
+ }
+ if (selectedButton != null && selectedComponent != null) {
+ selectedButton.setSelected(true);
+ }
+ }
+ }
+
+ private List<String> getFormatList(AttributePage attributePage) {
+ List<String> formatList = new ArrayList<String>();
+ for (String format : attributePage.getOutFormats()
+ .toUpperCase().split(",")) {
+ if (!"".equals(format)) {
+ formatList.add(format);
+ }
+ }
+ return formatList;
+ }
+
+ private JComponent createHorizontalBox(Color background) {
+ // using a JPanel instead of a Box as a workaround for bug 4907674
+ JPanel box = new JPanel();
+ box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
+ box.setBackground(background);
+ return box;
+ }
+
+ private JComponent createVerticalBox(Color background) {
+ // using a JPanel instead of a Box as a workaround for bug 4907674
+ JPanel box = new JPanel();
+ box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
+ box.setBackground(background);
+ return box;
+ }
+
+ private JComponent createBox(Component titleComponent, boolean fullBorder) {
+ JComponent box = createVerticalBox(componentBackgroundColor);
+ box.add(Box.createHorizontalStrut(400));
+ if (fullBorder) {
+ box.setBorder(new CompoundBorder(new LineBorder(borderColor, 1),
+ new EmptyBorder(10, 10, 10, 10)));
+ } else {
+ box.setBorder(new CompoundBorder(new SideBorder06(
+ SwingConstants.TOP, borderColor), new EmptyBorder(5, 10, 0,
+ 10)));
+ }
+ if (titleComponent != null) {
+ JComponent labelBox = createHorizontalBox(componentBackgroundColor);
+ labelBox.add(titleComponent);
+ labelBox.add(Box.createHorizontalGlue());
+ box.add(labelBox);
+ }
+ return box;
+ }
+
+ private void setSummaryCount(Query query, String datasetName, JLabel label)
+ throws MartServiceException {
+ if ("".equals(label.getText())) {
+ String count = null;
+ String total = null;
+ Query countQuery = new Query(query);
+ countQuery.removeAllDatasets();
+ countQuery.addDataset(new Dataset(datasetName));
+ countQuery.setCount(1);
+ countQuery.setFormatter(null);
+
+ Object[] results = martService.executeQuery(countQuery);
+ if (results.length == 1) {
+ if (results[0] instanceof List) {
+ List result = (List) results[0];
+ if (result.size() >= 1) {
+ total = (String) result.get(0);
+ // test for biomart's 'let add a random blank line'
+ // thing
+ if ("".equals(total) && result.size() > 1) {
+ total = (String) result.get(1);
+ }
+ try {
+ Integer.parseInt(total);
+ } catch (NumberFormatException e) {
+ total = "?";
+ }
+ }
+ }
+ }
+ Dataset dataset = query.getDataset(datasetName);
+ if (dataset != null && dataset.getFilters().size() > 0) {
+ Dataset countDataset = new Dataset(dataset);
+ countQuery.removeAllDatasets();
+ countQuery.addDataset(countDataset);
+ results = martService.executeQuery(countQuery);
+ if (results.length == 1) {
+ if (results[0] instanceof List) {
+ List result = (List) results[0];
+ if (result.size() >= 1) {
+ count = (String) result.get(0);
+ // test for biomart's 'let add a random blank
+ // line' thing
+ if ("".equals(count) && result.size() > 1) {
+ count = (String) result.get(1);
+ }
+ try {
+ Integer.parseInt(count);
+ } catch (NumberFormatException e) {
+ count = "";
+ }
+ }
+ }
+ }
+ } else {
+ count = total;
+ }
+
+ if (count != null && total != null) {
+ if (count.equals("")) {
+ label.setText("0 / " + total + " Genes");
+ } else {
+ label.setText(count + " / " + total + " Genes");
+ }
+ }
+
+ }
+ }
+
+ class TextFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private JTextField textField;
+
+ public TextFilterComponent(FilterDescription filterDescription,
+ MartDataset dataset) {
+ setConfigObject(filterDescription);
+ setDataset(dataset);
+ setName(filterDescription.getInternalName());
+ setLayout(new MinimalLayout(MinimalLayout.HORIZONTAL));
+ setBackground(componentBackgroundColor);
+
+ textField = new JTextField();
+ textField.setBackground(componentBackgroundColor);
+ textField.setPreferredSize(new Dimension(200, textField
+ .getPreferredSize().height + 4));
+
+ textField.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), textField.getText()));
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), textField.getText()));
+ }
+ });
+
+ add(textField);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponent#getType()
+ */
+ public int getType() {
+ return FILTER;
+ }
+
+ public void setValue(String value) {
+ textField.setText(value);
+ }
+
+ public String getValue() {
+ return textField.getText();
+ }
+
+ }
+
+ class MultipleTextFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private JTextArea textArea;
+
+ public MultipleTextFilterComponent(FilterDescription filterDescription,
+ MartDataset dataset) {
+ setConfigObject(filterDescription);
+ setDataset(dataset);
+ setName(filterDescription.getInternalName());
+ setLayout(new MinimalLayout(MinimalLayout.HORIZONTAL));
+ setBackground(componentBackgroundColor);
+
+ textArea = new JTextArea();
+ textArea.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), getValue()));
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), getValue()));
+ }
+ });
+
+ final JFileChooser chooser = new JFileChooser();
+ JButton chooserButton = new JButton("Browse...");
+ chooserButton.setBackground(componentBackgroundColor);
+ chooserButton.setFont(chooserButton.getFont()
+ .deriveFont(Font.PLAIN));
+ chooserButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int returnVal = chooser
+ .showOpenDialog(MultipleTextFilterComponent.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = chooser.getSelectedFile();
+ if (file != null && file.exists() && file.canRead()
+ && !file.isDirectory()) {
+ StringBuffer buffer = new StringBuffer();
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new FileReader(file));
+ String line = in.readLine();
+ while (line != null) {
+ buffer.append(line);
+ buffer.append(QueryConfigUtils.LINE_END);
+ line = in.readLine();
+ }
+ } catch (IOException e1) {
+ // no action
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e1) {
+ // give up
+ }
+ }
+ }
+ setValue(buffer.toString());
+ }
+ }
+ }
+ });
+
+ JPanel buttonPanel = new JPanel(new BorderLayout());
+ buttonPanel.setBackground(componentBackgroundColor);
+ buttonPanel.add(chooserButton, BorderLayout.WEST);
+
+ JScrollPane textScrollPane = new JScrollPane(textArea);
+ textScrollPane.setBackground(componentBackgroundColor);
+ textScrollPane.setPreferredSize(new Dimension(200, 80));
+
+ add(textScrollPane, BorderLayout.CENTER);
+ add(buttonPanel, BorderLayout.SOUTH);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponent#getType()
+ */
+ public int getType() {
+ return FILTER;
+ }
+
+ public void setValue(String value) {
+ textArea.setText(QueryConfigUtils.csvToValuePerLine(value));
+ }
+
+ public String getValue() {
+ return QueryConfigUtils.valuePerLineToCsv(textArea.getText());
+ }
+
+ }
+
+ class ListFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
+
+ private JComboBox comboBox;
+
+ private JTextField textField;
+
+ private Map optionMap = new HashMap();
+
+ private List optionList = new ArrayList();
+
+ private String dataset;
+
+ private Map componentMap;
+
+ private String type;
+
+ public ListFilterComponent(String refDataset,
+ FilterDescription filterDescription, MartDataset dataset,
+ Map componentMap) {
+ this.dataset = refDataset;
+ this.componentMap = componentMap;
+ setConfigObject(filterDescription);
+ setDataset(dataset);
+ setName(filterDescription.getInternalName());
+ setLayout(new BorderLayout());
+ setBackground(componentBackgroundColor);
+
+ Option[] options = filterDescription.getOptions();
+ // if there are no options but there is a default value then use the
+ // default value as an option
+ if (options.length == 0) {
+ String defaultValue = filterDescription.getDefaultValue();
+ if (defaultValue != null) {
+ Option newOption = new Option();
+ newOption.setInternalName(defaultValue);
+ newOption.setDisplayName(defaultValue);
+ newOption.setValue(defaultValue);
+ newOption.setSelectable("true");
+ options = new Option[] { newOption };
+ }
+ }
+
+ textField = new JTextField();
+ textField.setBackground(componentBackgroundColor);
+ textField.setPreferredSize(new Dimension(200, textField
+ .getPreferredSize().height + 4));
+
+ textField.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), textField.getText()));
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), textField.getText()));
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ fireFilterChanged(new QueryComponentEvent(this, getName(),
+ getDataset(), textField.getText()));
+ }
+ });
+
+ comboBox = new JComboBox();
+ comboBox.setFont(comboBox.getFont().deriveFont(Font.PLAIN));
+ comboBox.setBackground(componentBackgroundColor);
+ comboBox.setModel(comboBoxModel);
+
+ if (options.length == 0) {
+ add(textField, BorderLayout.WEST);
+ type = "text";
+ } else {
+ add(comboBox, BorderLayout.WEST);
+ type = "list";
+ }
+
+ setOptions(options);
+ // comboBox.setSelectedIndex(-1);
+
+ comboBox.addItemListener(new ItemListener() {
+
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ Option option = (Option) optionList.get(comboBox
+ .getSelectedIndex());
+ optionSelected(option);
+ ListFilterComponent.super.setValue(option.getValue());
+ fireFilterChanged(new QueryComponentEvent(this,
+ getName(), getDataset(), option.getValue()));
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ Option option = (Option) optionMap.get(getValue());
+ if (option != null) {
+ optionDeselected(option);
+ }
+ fireFilterChanged(new QueryComponentEvent(this,
+ getName(), getDataset(), ""));
+ }
+ }
+
+ });
+
+ }
+
+ public void setOptions(Option[] options) {
+ clearOptions();
+ for (int i = 0; i < options.length; i++) {
+ if (options[i].getHidden() == null
+ || !options[i].getHidden().equals("true")) {
+ optionMap.put(options[i].getValue(), options[i]);
+ optionList.add(options[i]);
+ String displayName = options[i].getDisplayName();
+ if (displayName != null) {
+ comboBoxModel.addElement(QueryConfigUtils
+ .truncateName(displayName));
+ }
+ }
+ }
+ if (optionList.size() > 0) {
+ if ("text".equals(type)) {
+ removeAll();
+ add(comboBox, BorderLayout.WEST);
+ type = "list";
+ revalidate();
+ repaint();
+ }
+ setValue(((Option) optionList.get(0)).getValue());
+ } else {
+ if ("list".equals(type)) {
+ removeAll();
+ add(textField, BorderLayout.WEST);
+ type = "text";
+ revalidate();
+ repaint();
+ }
+ }
+ }
+
+ private void clearOptions() {
+ comboBox.setSelectedIndex(-1);
+ comboBoxModel.removeAllElements();
+ optionMap.clear();
+ optionList.clear();
+ }
+
+ public void setValue(String value) {
+ if ("list".equals(type)) {
+ if (value == null) {
+ if (getValue() != null) {
+ optionDeselected((Option) optionMap.get(getValue()));
+ comboBox.setSelectedIndex(-1);
+ }
+ } else {
+ if (getValue() != null) {
+ Option option = (Option) optionMap.get(getValue());
+ if (option != null) {
+ optionDeselected(option);
+ }
+ }
+ Option option = (Option) optionMap.get(value);
+ if (option != null) {
+ optionSelected(option);
+ }
+ int index = optionList.indexOf(option);
+ comboBox.setSelectedIndex(index);
+ }
+ } else if ("text".equals(type)) {
+ textField.setText(value);
+ }
+ super.setValue(value);
+ }
+
+ private void optionSelected(Option option) {
+ if (option == null) {
+ logger.info("null option for " + getName());
+ } else {
+ PushAction[] pushActions = option.getPushActions();
+ for (int i = 0; i < pushActions.length; i++) {
+ QueryComponent queryComponent = getReferencedComponent(pushActions[i]);
+ if (queryComponent instanceof ListFilterComponent) {
+ ListFilterComponent filterComponent = (ListFilterComponent) queryComponent;
+ if (filterComponent != null) {
+ filterComponent.setOptions(pushActions[i]
+ .getOptions());
+ }
+ }
+ }
+ }
+ }
+
+ private void optionDeselected(Option option) {
+ PushAction[] pushActions = option.getPushActions();
+ for (int i = 0; i < pushActions.length; i++) {
+ QueryComponent queryComponent = getReferencedComponent(pushActions[i]);
+ if (queryComponent instanceof ListFilterComponent) {
+ ListFilterComponent filterComponent = (ListFilterComponent) queryComponent;
+ if (filterComponent != null) {
+ filterComponent.clearOptions();
+ }
+ }
+ }
+ }
+
+ private QueryComponent getReferencedComponent(PushAction pushAction) {
+ String ref = pushAction.getRef();
+ if (ref.indexOf('.') == -1) {
+ return (QueryComponent) componentMap.get(dataset + "." + ref);
+ } else {
+ return (QueryComponent) componentMap.get(ref);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponent#getType()
+ */
+ public int getType() {
+ return FILTER;
+ }
+ }
+
+ class IdListFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
+
+ private JComboBox comboBox;
+
+ private JTextArea textArea;
+
+ private Map<String, QueryComponent> componentMap = new HashMap<String, QueryComponent>();
+
+ private List<String> filterList = new ArrayList<String>();
+
+ private int currentIndex;
+
+ private boolean valueChanging;
+
+ public IdListFilterComponent(FilterDescription description,
+ MartDataset dataset, List<TextFilterComponent> filterComponentList) {
+ setLayout(new MinimalLayout(MinimalLayout.VERTICAL));
+ setBackground(componentBackgroundColor);
+
+ comboBox = new JComboBox();
+ comboBox.setFont(comboBox.getFont().deriveFont(Font.PLAIN));
+ comboBox.setBackground(componentBackgroundColor);
+ comboBox.setModel(comboBoxModel);
+
+ for (TextFilterComponent filterComponent : filterComponentList) {
+ BaseNamedConfigurationObject filterDescription = filterComponent
+ .getConfigObject();
+ componentMap.put(filterDescription.getInternalName(),
+ filterComponent);
+ filterList.add(filterDescription.getInternalName());
+ comboBoxModel.addElement(filterDescription.getDisplayName());
+ filterToDisplayName.put(filterDescription.getInternalName(),
+ filterDescription.getDisplayName());
+ filterComponent
+ .addQueryComponentListener(new QueryComponentAdapter() {
+ public void filterAdded(QueryComponentEvent event) {
+ if (!valueChanging) {
+ valueChanging = true;
+ comboBox.setSelectedIndex(filterList
+ .indexOf(event.getName()));
+ selectorButton.setSelected(true);
+ valueChanging = false;
+ }
+ }
+
+ public void filterRemoved(QueryComponentEvent event) {
+ if (!valueChanging) {
+ valueChanging = true;
+ selectorButton.setSelected(false);
+ valueChanging = false;
+ }
+ }
+
+ public void filterChanged(QueryComponentEvent event) {
+ if (!valueChanging) {
+ valueChanging = true;
+ textArea
+ .setText(QueryConfigUtils
+ .csvToValuePerLine(event
+ .getValue()));
+ valueChanging = false;
+ }
+ }
+ });
+ filterComponent.setSelectorButton(new JCheckBox());
+ }
+
+ comboBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ int selectedIndex = comboBox.getSelectedIndex();
+ if (selectorButton.isSelected()) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ if (!valueChanging) {
+ valueChanging = true;
+ QueryComponent queryComponent = componentMap
+ .get(filterList.get(selectedIndex));
+ queryComponent.setValue(QueryConfigUtils
+ .valuePerLineToCsv(textArea.getText()));
+ queryComponent.setSelected(true);
+ valueChanging = false;
+ }
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ if (!valueChanging) {
+ valueChanging = true;
+ componentMap.get(filterList
+ .get(currentIndex)).setSelected(false);
+ valueChanging = false;
+ }
+ }
+ }
+ currentIndex = selectedIndex;
+ }
+ });
+
+ textArea = new JTextArea();
+ textArea.getDocument().addDocumentListener(new DocumentListener() {
+ public void changedUpdate(DocumentEvent e) {
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ updateValue();
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ updateValue();
+ }
+
+ private void updateValue() {
+ if (!valueChanging) {
+ valueChanging = true;
+ int selectedIndex = comboBox.getSelectedIndex();
+ String value = QueryConfigUtils
+ .valuePerLineToCsv(textArea.getText());
+ componentMap.get(filterList
+ .get(selectedIndex)).setValue(value);
+ valueChanging = false;
+ }
+ }
+ });
+
+ final JFileChooser chooser = new JFileChooser();
+ JButton chooserButton = new JButton("Browse...");
+ chooserButton.setBackground(componentBackgroundColor);
+ chooserButton.setFont(chooserButton.getFont()
+ .deriveFont(Font.PLAIN));
+ chooserButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int returnVal = chooser
+ .showOpenDialog(IdListFilterComponent.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = chooser.getSelectedFile();
+ if (file != null && file.exists() && file.canRead()
+ && !file.isDirectory()) {
+ StringBuffer buffer = new StringBuffer();
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new FileReader(file));
+ String line = in.readLine();
+ while (line != null) {
+ buffer.append(line);
+ buffer.append(QueryConfigUtils.LINE_END);
+ line = in.readLine();
+ }
+ } catch (IOException e1) {
+ // no action
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e1) {
+ // give up
+ }
+ }
+ }
+ textArea.setText(buffer.toString());
+ }
+ }
+ }
+ });
+
+ JPanel buttonPanel = new JPanel(new BorderLayout());
+ buttonPanel.setBackground(componentBackgroundColor);
+ buttonPanel.add(chooserButton, BorderLayout.WEST);
+
+ JScrollPane textScrollPane = new JScrollPane(textArea);
+ textScrollPane.setBackground(componentBackgroundColor);
+ textScrollPane.setPreferredSize(new Dimension(200, 80));
+
+ add(comboBox, BorderLayout.NORTH);
+ add(textScrollPane, BorderLayout.CENTER);
+ add(buttonPanel, BorderLayout.SOUTH);
+
+ }
+
+ public void setSelectorButton(AbstractButton button) {
+ selectorButton = button;
+ button.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ int selectedIndex = comboBox.getSelectedIndex();
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ if (!valueChanging) {
+ valueChanging = true;
+ QueryComponent queryComponent = componentMap
+ .get(filterList.get(selectedIndex));
+ queryComponent.setValue(QueryConfigUtils
+ .valuePerLineToCsv(textArea.getText()));
+ queryComponent.setSelected(true);
+ valueChanging = false;
+ }
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ if (!valueChanging) {
+ valueChanging = true;
+ componentMap.get(filterList
+ .get(selectedIndex)).setSelected(false);
+ valueChanging = false;
+ }
+ }
+ }
+ });
+
+ }
+
+ public int getType() {
+ return FILTER;
+ }
+
+ }
+
+ class BooleanListFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
+
+ private JComboBox comboBox;
+
+ private BooleanFilterComponent booleanFilterComponent;
+
+ private Map componentMap = new HashMap();
+
+ private List<String> filterList = new ArrayList<String>();
+
+ private int currentIndex;
+
+ public BooleanListFilterComponent(FilterDescription description,
+ MartDataset dataset, List filterComponentList) {
+ setLayout(new MinimalLayout(MinimalLayout.HORIZONTAL));
+ setBackground(componentBackgroundColor);
+
+ comboBox = new JComboBox();
+ comboBox.setFont(comboBox.getFont().deriveFont(Font.PLAIN));
+ comboBox.setBackground(componentBackgroundColor);
+ comboBox.setModel(comboBoxModel);
+
+ for (Iterator iter = filterComponentList.iterator(); iter.hasNext();) {
+ BooleanFilterComponent filterComponent = (BooleanFilterComponent) iter
+ .next();
+ BaseNamedConfigurationObject filterDescription = filterComponent
+ .getConfigObject();
+ componentMap.put(filterDescription.getInternalName(),
+ filterComponent);
+ filterList.add(filterDescription.getInternalName());
+ comboBoxModel.addElement(filterDescription.getDisplayName());
+ filterToDisplayName.put(filterDescription.getInternalName(),
+ filterDescription.getDisplayName());
+ filterComponent
+ .addQueryComponentListener(new QueryComponentAdapter() {
+ public void filterAdded(QueryComponentEvent event) {
+ comboBox.setSelectedIndex(filterList
+ .indexOf(event.getName()));
+ selectorButton.setSelected(true);
+ }
+
+ public void filterChanged(QueryComponentEvent event) {
+ booleanFilterComponent.setValue(event
+ .getValue());
+ }
+ });
+ filterComponent.setSelectorButton(new JCheckBox());
+ }
+
+ comboBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ int selectedIndex = comboBox.getSelectedIndex();
+ if (selectorButton.isSelected()) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ QueryComponent queryComponent = (QueryComponent) componentMap
+ .get(filterList.get(selectedIndex));
+ queryComponent.setValue(booleanFilterComponent
+ .getValue());
+ queryComponent.setSelected(true);
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ ((QueryComponent) componentMap.get(filterList
+ .get(currentIndex))).setSelected(false);
+ }
+ }
+ currentIndex = selectedIndex;
+ }
+ });
+
+ booleanFilterComponent = new BooleanFilterComponent(
+ new FilterDescription(), dataset);
+ booleanFilterComponent
+ .addQueryComponentListener(new QueryComponentAdapter() {
+ public void filterChanged(QueryComponentEvent event) {
+ int selectedIndex = comboBox.getSelectedIndex();
+ ((QueryComponent) componentMap.get(filterList
+ .get(selectedIndex))).setValue(event
+ .getValue());
+ }
+ });
+
+ JPanel comboBoxPanel = new JPanel(new MinimalLayout());
+ comboBoxPanel.setBackground(componentBackgroundColor);
+ comboBoxPanel.setBorder(new EmptyBorder(5, 5, 0, 0));
+ add(comboBox);
+ add(booleanFilterComponent);
+ }
+
+ public void setSelectorButton(AbstractButton button) {
+ selectorButton = button;
+ button.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ int selectedIndex = comboBox.getSelectedIndex();
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ QueryComponent queryComponent = (QueryComponent) componentMap
+ .get(filterList.get(selectedIndex));
+ queryComponent.setValue(booleanFilterComponent
+ .getValue());
+ queryComponent.setSelected(true);
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ ((QueryComponent) componentMap.get(filterList
+ .get(selectedIndex))).setSelected(false);
+ }
+ }
+ });
+ }
+
+ public int getType() {
+ return FILTER;
+ }
+
+ }
+
+ class BooleanFilterComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private static final String ONLY = "only";
+
+ private static final String EXCLUDED = "excluded";
+
+ private ButtonGroup buttonGroup = new ButtonGroup();
+
+ private JRadioButton only;
+
+ private JRadioButton excluded;
+
+ public BooleanFilterComponent(FilterDescription filterDescription,
+ MartDataset dataset) {
+ setConfigObject(filterDescription);
+ setDataset(dataset);
+ setName(filterDescription.getInternalName());
+ setBackground(componentBackgroundColor);
+
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setBackground(componentBackgroundColor);
+
+ only = new JRadioButton("Only");
+ only.setFont(only.getFont().deriveFont(Font.PLAIN));
+ only.setBackground(componentBackgroundColor);
+ only.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ fireFilterChanged(new QueryComponentEvent(this,
+ getName(), getDataset(), ONLY));
+ }
+ }
+ });
+ buttonGroup.add(only);
+ add(only);
+
+ excluded = new JRadioButton("Excluded");
+ excluded.setFont(excluded.getFont().deriveFont(Font.PLAIN));
+ excluded.setBackground(componentBackgroundColor);
+ excluded.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ fireFilterChanged(new QueryComponentEvent(this,
+ getName(), getDataset(), EXCLUDED));
+ }
+ }
+ });
+ buttonGroup.add(excluded);
+ add(excluded);
+
+ setValue(filterDescription.getQualifier());
+ }
+
+ public int getType() {
+ return FILTER;
+ }
+
+ public String getValue() {
+ if (excluded.isSelected()) {
+ return EXCLUDED;
+ } else {
+ return ONLY;
+ }
+ }
+
+ public void setValue(String value) {
+ if (EXCLUDED.equals(value)) {
+ excluded.setSelected(true);
+ } else {
+ only.setSelected(true);
+ }
+ }
+
+ }
+
+ class AttributeComponent extends QueryComponent {
+ private static final long serialVersionUID = 1L;
+
+ private AbstractButton button;
+
+ private AbstractButton offButton;
+
+ public AttributeComponent(
+ BaseNamedConfigurationObject attributeDescription,
+ MartDataset dataset, Object offButton) {
+ this.offButton = (AbstractButton) offButton;
+ setConfigObject(attributeDescription);
+ setDataset(dataset);
+ setName(attributeDescription.getInternalName());
+ if (attributeDescription instanceof AttributeList) {
+ setValue(((AttributeList) attributeDescription).getAttributes());
+ }
+ setLayout(new BorderLayout());
+ setBackground(componentBackgroundColor);
+ // if there's no display name the attribute isn't displayed
+ String displayName = attributeDescription.getDisplayName();
+ if (displayName != null) {
+ attributeToDisplayName.put(attributeDescription
+ .getInternalName(), displayName);
+ if (offButton != null) {
+ button = new JRadioButton(QueryConfigUtils
+ .splitSentence(displayName));
+ } else {
+ button = new JCheckBox(QueryConfigUtils
+ .splitSentence(displayName));
+ }
+ button.setFont(button.getFont().deriveFont(Font.PLAIN));
+ button.setBackground(componentBackgroundColor);
+ setSelectorButton(button);
+
+ String description = attributeDescription.getDescription();
+ if (description != null) {
+ button.setToolTipText(description);
+ }
+
+ add(button, BorderLayout.WEST);
+
+ button.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (!settingAttributeState) {
+ settingAttributeState = true;
+ List attributes = (List) attributeNameToComponentMap
+ .get(getQualifiedName());
+ if (attributes != null) {
+ for (Iterator iter = attributes.iterator(); iter
+ .hasNext();) {
+ AttributeComponent attribute = (AttributeComponent) iter
+ .next();
+ if (attribute != AttributeComponent.this) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ attribute.setSelected(true);
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ attribute.setSelected(false);
+ }
+ }
+ }
+ }
+ settingAttributeState = false;
+ }
+ }
+ });
+ }
+ }
+
+ public int getType() {
+ return ATTRIBUTE;
+ }
+
+ public void setSelected(boolean selected) {
+ if (offButton != null) {
+ if (selected) {
+ button.setSelected(true);
+ } else {
+ offButton.setSelected(true);
+ }
+ }
<TRUNCATED>
[07/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddMobyParseDatatypeEdit.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddMobyParseDatatypeEdit.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddMobyParseDatatypeEdit.java
new file mode 100644
index 0000000..43bc61f
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddMobyParseDatatypeEdit.java
@@ -0,0 +1,220 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.edits;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivity;
+import net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivityConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.EventForwardingOutputPort;
+import net.sf.taverna.t2.workflowmodel.EventHandlingInputPort;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorOutputPort;
+import net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit;
+import net.sf.taverna.t2.workflowmodel.impl.DataflowImpl;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class AddMobyParseDatatypeEdit extends AbstractDataflowEdit {
+
+ private final BiomobyActivity activity;
+ private final String objectName;
+ private final boolean isCollection;
+ private final String potentialCollectionString;
+
+ private Edit<?> compoundEdit = null;
+ private Edit<?> linkEdit = null;
+
+ private Edits edits;
+
+ /**
+ * @param dataflow
+ */
+ public AddMobyParseDatatypeEdit(Dataflow dataflow,
+ BiomobyActivity activity, String objectName, boolean isCollection,
+ String potentialCollectionString, Edits edits) {
+ super(dataflow);
+ this.activity = activity;
+ this.objectName = objectName;
+ this.isCollection = isCollection;
+ this.potentialCollectionString = potentialCollectionString;
+ this.edits = edits;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractEdit#doEditAction(java.lang
+ * .Object)
+ */
+ @Override
+ protected void doEditAction(DataflowImpl dataflow) throws EditException {
+
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+
+ String defaultName = objectName;
+ if (defaultName.indexOf("(") > 0)
+ defaultName = defaultName.substring(0, defaultName.indexOf("("));
+
+ String name = Tools
+ .uniqueProcessorName("Parse Moby Data(" + defaultName + ")",
+ dataflow);
+
+ String articlename = "";
+ if (isCollection) {
+ articlename = potentialCollectionString.substring(
+ potentialCollectionString.indexOf("('") + 2,
+ potentialCollectionString.lastIndexOf("'"));
+ } else {
+ articlename = objectName.substring(objectName.indexOf("'") + 1,
+ objectName.lastIndexOf("'"));
+ }
+
+ MobyParseDatatypeActivityConfigurationBean bean = new MobyParseDatatypeActivityConfigurationBean();
+ bean.setArticleNameUsedByService(articlename);
+ bean.setRegistryEndpoint(activity.getConfiguration().getMobyEndpoint());
+ bean.setDatatypeName(defaultName);
+ MobyParseDatatypeActivity mobyDatatypeActivity = new MobyParseDatatypeActivity();
+
+ editList
+ .add(edits.getConfigureActivityEdit(mobyDatatypeActivity, bean));
+
+ net.sf.taverna.t2.workflowmodel.Processor sinkProcessor = edits
+ .createProcessor(name);
+
+ editList.add(edits.getDefaultDispatchStackEdit(sinkProcessor));
+
+ Edit<?> addActivityToProcessorEdit = edits.getAddActivityEdit(
+ sinkProcessor, mobyDatatypeActivity);
+ editList.add(addActivityToProcessorEdit);
+
+ editList.add(edits.getAddProcessorEdit(dataflow, sinkProcessor));
+
+ compoundEdit = new CompoundEdit(editList);
+ compoundEdit.doEdit();
+
+ Processor sourceProcessor = Tools.getProcessorsWithActivity(dataflow,
+ activity).iterator().next();
+
+ List<Edit<?>> linkEditList = new ArrayList<Edit<?>>();
+
+ String inputName = mobyDatatypeActivity.getInputPorts().iterator()
+ .next().getName();
+ EventHandlingInputPort sinkPort = getSinkPort(sinkProcessor,
+ mobyDatatypeActivity, inputName, linkEditList);
+
+
+ String outputPortName;
+ if (isCollection) {
+ outputPortName = defaultName + "(Collection - '"
+ + (articlename.equals("") ? "MobyCollection" : articlename)
+ + "' As Simples)";
+ }
+ else {
+ outputPortName = defaultName +"(" + articlename + ")";
+ }
+ EventForwardingOutputPort sourcePort = getSourcePort(sourceProcessor,
+ activity, outputPortName, linkEditList);
+ linkEditList.add(Tools.getCreateAndConnectDatalinkEdit(dataflow,
+ sourcePort, sinkPort, edits));
+ linkEdit = new CompoundEdit(linkEditList);
+ linkEdit.doEdit();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractEdit#undoEditAction(java
+ * .lang.Object)
+ */
+ @Override
+ protected void undoEditAction(DataflowImpl subjectImpl) {
+ if (linkEdit != null && linkEdit.isApplied())
+ linkEdit.undo();
+ if (compoundEdit != null && compoundEdit.isApplied())
+ compoundEdit.undo();
+ }
+
+ private EventHandlingInputPort getSinkPort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ InputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityInputPort(activity, portName);
+ // check if processor port exists
+ EventHandlingInputPort input = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorInputPort(processor, activity, activityPort);
+ if (input == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorInputPort processorInputPort = edits
+ .createProcessorInputPort(processor,
+ activityPort.getName(), activityPort.getDepth());
+ editList.add(edits.getAddProcessorInputPortEdit(processor,
+ processorInputPort));
+ editList.add(edits.getAddActivityInputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ input = processorInputPort;
+ }
+ return input;
+ }
+
+ private EventForwardingOutputPort getSourcePort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ OutputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityOutputPort(activity, portName);
+ // check if processor port exists
+ EventForwardingOutputPort output = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorOutputPort(processor, activity, activityPort);
+ if (output == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorOutputPort processorOutputPort = edits
+ .createProcessorOutputPort(processor, activityPort
+ .getName(), activityPort.getDepth(), activityPort
+ .getGranularDepth());
+ editList.add(edits.getAddProcessorOutputPortEdit(processor,
+ processorOutputPort));
+ editList.add(edits.getAddActivityOutputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ output = processorOutputPort;
+ }
+ return output;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddUpstreamObjectEdit.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddUpstreamObjectEdit.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddUpstreamObjectEdit.java
new file mode 100644
index 0000000..fea1860
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddUpstreamObjectEdit.java
@@ -0,0 +1,216 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.edits;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.EventForwardingOutputPort;
+import net.sf.taverna.t2.workflowmodel.EventHandlingInputPort;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorOutputPort;
+import net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit;
+import net.sf.taverna.t2.workflowmodel.impl.DataflowImpl;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class AddUpstreamObjectEdit extends AbstractDataflowEdit {
+
+ private static Logger logger = Logger.getLogger(AddUpstreamObjectEdit.class);
+
+ private final Processor sinkProcessor;
+ private final BiomobyObjectActivity activity;
+ private Edits edits;
+
+ private List<Edit<?>> subEdits = new ArrayList<Edit<?>>();
+
+ /**
+ * @param dataflow
+ */
+ public AddUpstreamObjectEdit(Dataflow dataflow, Processor sinkProcessor,
+ BiomobyObjectActivity activity, Edits edits) {
+ super(dataflow);
+ this.sinkProcessor = sinkProcessor;
+ this.activity = activity;
+ this.edits = edits;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit#doEditAction
+ * (net.sf.taverna.t2.workflowmodel.impl.DataflowImpl)
+ */
+ @Override
+ protected void doEditAction(DataflowImpl dataflow) throws EditException {
+ subEdits.clear();
+
+ for (InputPort inputPort : activity.getInputPorts()) {
+ // ignore article name, id, namespace, value
+ if (inputPort.getName().equals("namespace")
+ || inputPort.getName().equals("id")
+ || inputPort.getName().equals("article name")
+ || inputPort.getName().equals("value")) {
+ continue;
+ }
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+ String defaultName = inputPort.getName().split("\\(")[0];
+
+ String name = Tools
+ .uniqueProcessorName(inputPort.getName(), dataflow);
+
+ BiomobyObjectActivityConfigurationBean configBean = new BiomobyObjectActivityConfigurationBean();
+ configBean.setMobyEndpoint(activity.getConfiguration()
+ .getMobyEndpoint());
+ configBean.setAuthorityName("");
+ configBean.setServiceName(defaultName);
+
+ net.sf.taverna.t2.workflowmodel.Processor sourceProcessor = edits
+ .createProcessor(name);
+ BiomobyObjectActivity boActivity = new BiomobyObjectActivity();
+ Edit<?> configureActivityEdit = edits.getConfigureActivityEdit(
+ boActivity, configBean);
+ editList.add(configureActivityEdit);
+
+ editList.add(edits.getDefaultDispatchStackEdit(sourceProcessor));
+
+ Edit<?> addActivityToProcessorEdit = edits.getAddActivityEdit(
+ sourceProcessor, boActivity);
+ editList.add(addActivityToProcessorEdit);
+
+
+
+ editList.add(edits.getAddProcessorEdit(dataflow, sourceProcessor));
+
+ CompoundEdit compoundEdit = new CompoundEdit(editList);
+ subEdits.add(compoundEdit);
+ compoundEdit.doEdit();
+
+
+ List<Edit<?>> linkEditList = new ArrayList<Edit<?>>();
+
+ EventForwardingOutputPort sourcePort = getSourcePort(
+ sourceProcessor, boActivity, "mobyData", linkEditList);
+ EventHandlingInputPort sinkPort = getSinkPort(sinkProcessor, activity, inputPort.getName(), linkEditList);
+ linkEditList.add(Tools.getCreateAndConnectDatalinkEdit(dataflow,
+ sourcePort, sinkPort, edits));
+ CompoundEdit linkEdit = new CompoundEdit(linkEditList);
+ subEdits.add(linkEdit);
+ linkEdit.doEdit();
+
+ if (!(defaultName.equalsIgnoreCase("Object")
+ || name.equalsIgnoreCase("String")
+ || name.equalsIgnoreCase("Integer") || name
+ .equalsIgnoreCase("DateTime"))) {
+ Edit upstreamObjectEdit = new AddUpstreamObjectEdit(dataflow,
+ sourceProcessor, boActivity, edits);
+ subEdits.add(upstreamObjectEdit);
+ upstreamObjectEdit.doEdit();
+ }
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit#undoEditAction
+ * (net.sf.taverna.t2.workflowmodel.impl.DataflowImpl)
+ */
+ @Override
+ protected void undoEditAction(DataflowImpl dataflow) {
+ if (subEdits != null && subEdits.size() > 0) {
+ for (int i = subEdits.size() - 1; i >= 0; i--) {
+ Edit<?> edit = subEdits.get(i);
+ if (edit.isApplied())
+ edit.undo();
+ }
+ }
+
+
+ }
+
+ private EventHandlingInputPort getSinkPort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ InputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityInputPort(activity, portName);
+ // check if processor port exists
+ EventHandlingInputPort input = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorInputPort(processor, activity, activityPort);
+ if (input == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorInputPort processorInputPort = edits
+ .createProcessorInputPort(processor,
+ activityPort.getName(), activityPort.getDepth());
+ editList.add(edits.getAddProcessorInputPortEdit(processor,
+ processorInputPort));
+ editList.add(edits.getAddActivityInputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ input = processorInputPort;
+ }
+ return input;
+ }
+
+ private EventForwardingOutputPort getSourcePort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ OutputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityOutputPort(activity, portName);
+ // check if processor port exists
+ EventForwardingOutputPort output = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorOutputPort(processor, activity, activityPort);
+ if (output == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorOutputPort processorOutputPort = edits
+ .createProcessorOutputPort(processor, activityPort
+ .getName(), activityPort.getDepth(), activityPort
+ .getGranularDepth());
+ editList.add(edits.getAddProcessorOutputPortEdit(processor,
+ processorOutputPort));
+ editList.add(edits.getAddActivityOutputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ output = processorOutputPort;
+ }
+ return output;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityDetailsMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityDetailsMenuAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityDetailsMenuAction.java
new file mode 100644
index 0000000..cee5420
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityDetailsMenuAction.java
@@ -0,0 +1,40 @@
+package net.sf.taverna.t2.activities.biomoby.menu;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyServiceDetailsAction;
+import net.sf.taverna.t2.workbench.activitytools.AbstractConfigureActivityMenuAction;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workflowmodel.Edits;
+
+public class BiomobyActivityDetailsMenuAction extends
+ AbstractConfigureActivityMenuAction<BiomobyActivity> {
+
+ private static final String CONFIGURE_BIOMOBY_DETAILS = "Browse Biomoby service details";
+ private EditManager editManager;
+ private FileManager fileManager;
+
+ public BiomobyActivityDetailsMenuAction() {
+ super(BiomobyActivity.class);
+ }
+
+ @Override
+ protected Action createAction() {
+ MobyServiceDetailsAction configAction = new MobyServiceDetailsAction(
+ findActivity(), getParentFrame(), editManager, fileManager);
+ configAction.putValue(Action.NAME, CONFIGURE_BIOMOBY_DETAILS);
+ addMenuDots(configAction);
+ return configAction;
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityParserMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityParserMenuAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityParserMenuAction.java
new file mode 100644
index 0000000..b760bbc
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/BiomobyActivityParserMenuAction.java
@@ -0,0 +1,41 @@
+package net.sf.taverna.t2.activities.biomoby.menu;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyParserAction;
+import net.sf.taverna.t2.workbench.activitytools.AbstractConfigureActivityMenuAction;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+
+public class BiomobyActivityParserMenuAction extends
+ AbstractConfigureActivityMenuAction<BiomobyActivity> {
+
+ private static final String ADD_BIOMOBY_PARSER = "Add Biomoby parser";
+
+ private EditManager editManager;
+
+ private FileManager fileManager;
+
+ public BiomobyActivityParserMenuAction() {
+ super(BiomobyActivity.class);
+ }
+
+ @Override
+ protected Action createAction() {
+ MobyParserAction configAction = new MobyParserAction(
+ findActivity(), getParentFrame(), editManager, fileManager);
+ configAction.putValue(Action.NAME, ADD_BIOMOBY_PARSER);
+ addMenuDots(configAction);
+ return configAction;
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/ConfigureBiomobyMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/ConfigureBiomobyMenuAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/ConfigureBiomobyMenuAction.java
new file mode 100644
index 0000000..b86df2a
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/menu/ConfigureBiomobyMenuAction.java
@@ -0,0 +1,52 @@
+package net.sf.taverna.t2.activities.biomoby.menu;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.actions.BiomobyActivityConfigurationAction;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.activitytools.AbstractConfigureActivityMenuAction;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+
+public class ConfigureBiomobyMenuAction extends
+ AbstractConfigureActivityMenuAction<BiomobyActivity> {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+
+ public ConfigureBiomobyMenuAction() {
+ super(BiomobyActivity.class);
+ }
+
+ @Override
+ protected Action createAction() {
+ BiomobyActivity a = findActivity();
+ Action result = null;
+ result = new BiomobyActivityConfigurationAction(a, getParentFrame(), editManager,
+ fileManager, activityIconManager);
+ result.putValue(Action.NAME, "Configure");
+ addMenuDots(result);
+ return result;
+ }
+
+ public boolean isEnabled() {
+ BiomobyActivity activity = findActivity();
+ return (super.isEnabled() && (activity.getMobyService() != null) && activity
+ .containsSecondaries());
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityIcon.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityIcon.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityIcon.java
new file mode 100644
index 0000000..2c28c32
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityIcon.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.query;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+/**
+ *
+ * @author Alex Nenadic
+ *
+ */
+public class BiomobyActivityIcon implements ActivityIconSPI{
+
+ public int canProvideIconScore(Activity<?> activity) {
+ if (activity.getClass().getName().equals(BiomobyActivity.class.getName()))
+ return DEFAULT_ICON + 1;
+ else
+ return NO_ICON;
+ }
+
+ public Icon getIcon(Activity<?> activity) {
+ return getBiomobyIcon();
+ }
+
+ public static Icon getBiomobyIcon() {
+ return new ImageIcon(BiomobyActivityIcon.class.getResource("/registry.gif"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityItem.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityItem.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityItem.java
new file mode 100644
index 0000000..a799280
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyActivityItem.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.query;
+
+
+public class BiomobyActivityItem /*extends AbstractActivityItem */{
+
+ String registryUrl;
+ String serviceName;
+ String authorityName;
+ String registryUri;
+ String category;
+ String serviceType;
+
+ public String getRegistryUri() {
+ return registryUri;
+ }
+
+ public void setRegistryUri(String registryUri) {
+ this.registryUri = registryUri;
+ }
+
+ public String getRegistryUrl() {
+ return registryUrl;
+ }
+
+ public void setRegistryUrl(String registryUrl) {
+ this.registryUrl = registryUrl;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+// @Override
+// public Object getConfigBean() {
+// BiomobyActivityConfigurationBean bean = new BiomobyActivityConfigurationBean();
+// bean.setAuthorityName(getAuthorityName());
+// bean.setServiceName(getServiceName());
+// bean.setMobyEndpoint(getRegistryUrl());
+// return bean;
+// }
+//
+// @Override
+// public Icon getIcon() {
+// return BiomobyActivityIcon.getBiomobyIcon();
+// }
+//
+// @Override
+// public Activity<?> getUnconfiguredActivity() {
+// return new BiomobyActivity();
+// }
+
+ public String getType() {
+ return "Biomoby";
+ }
+
+ @Override
+ public String toString() {
+ return getServiceName();
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityIcon.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityIcon.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityIcon.java
new file mode 100644
index 0000000..f4575e4
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityIcon.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.query;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+/**
+ *
+ * @author Alex Nenadic
+ *
+ */
+public class BiomobyObjectActivityIcon implements ActivityIconSPI{
+
+ public int canProvideIconScore(Activity<?> activity) {
+ if (activity.getClass().getName().equals(BiomobyObjectActivity.class.getName()))
+ return DEFAULT_ICON + 1;
+ else
+ return NO_ICON;
+ }
+
+ public Icon getIcon(Activity<?> activity) {
+ return new ImageIcon(BiomobyObjectActivityIcon.class.getResource("/biomoby_object.png"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityItem.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityItem.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityItem.java
new file mode 100644
index 0000000..1e50d37
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyObjectActivityItem.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.query;
+
+
+/**
+ *
+ * @author Alex Nenadic
+ * @author Stuart Owen
+ *
+ */
+public class BiomobyObjectActivityItem /*extends AbstractActivityItem*/ {
+
+ String registryUrl;
+ String serviceName;
+ String authorityName;
+ String registryUri;
+
+ public String getRegistryUri() {
+ return registryUri;
+ }
+
+ public void setRegistryUri(String registryUri) {
+ this.registryUri = registryUri;
+ }
+
+ public String getRegistryUrl() {
+ return registryUrl;
+ }
+
+ public void setRegistryUrl(String registryUrl) {
+ this.registryUrl = registryUrl;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+// @Override
+// public Object getConfigBean() {
+// BiomobyObjectActivityConfigurationBean bean = new BiomobyObjectActivityConfigurationBean();
+// bean.setAuthorityName(getAuthorityName());
+// bean.setServiceName(getServiceName());
+// bean.setMobyEndpoint(getRegistryUrl());
+// return bean;
+// }
+//
+// @Override
+// public Icon getIcon() {
+// return new ImageIcon(BiomobyObjectActivityItem.class.getResource("/biomoby_object.png"));
+// }
+//
+// @Override
+// public Activity<?> getUnconfiguredActivity() {
+// return new BiomobyObjectActivity();
+// }
+
+ public String getType() {
+ return "Biomoby Object";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyQueryHelper.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyQueryHelper.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyQueryHelper.java
new file mode 100644
index 0000000..e22b78c
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/BiomobyQueryHelper.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.query;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import net.sf.taverna.raven.appconfig.ApplicationRuntime;
+import net.sf.taverna.t2.activities.biomoby.GetOntologyThread;
+import net.sf.taverna.t2.activities.biomoby.datatypedescriptions.BiomobyDatatypeDescription;
+import net.sf.taverna.t2.activities.biomoby.servicedescriptions.BiomobyServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider.FindServiceDescriptionsCallBack;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralDigestCachedImpl;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyService;
+import org.w3c.dom.Document;
+
+public class BiomobyQueryHelper {
+
+ private static Logger log = Logger.getLogger(BiomobyQueryHelper.class);
+
+ private String registryNamespace;
+ private String registryEndpoint;
+
+ private CentralDigestCachedImpl central;
+
+ private String DEFAULT_REGISTRY_ENDPOINT = CentralImpl.DEFAULT_ENDPOINT;
+
+ private String DEFAULT_REGISTRY_NAMESPACE = CentralImpl.DEFAULT_NAMESPACE;
+
+ private String remoteDatatypeRdfUrl = null;
+
+ private String remoteServiceRdfUrl = null;
+
+ private static final String CACHE_NAME = "moby-cache";
+
+ private ApplicationRuntime applicationRuntime = ApplicationRuntime
+ .getInstance();
+
+ public BiomobyQueryHelper(String registryEndpoint, String registryNamespace)
+ throws MobyException {
+ try {
+ if (registryNamespace != null)
+ this.registryNamespace = registryNamespace;
+ else
+ this.registryNamespace = DEFAULT_REGISTRY_NAMESPACE;
+ if (registryEndpoint != null)
+ this.registryEndpoint = registryEndpoint;
+ else
+ this.registryEndpoint = DEFAULT_REGISTRY_ENDPOINT;
+ String tavernaHome = null;
+ if (applicationRuntime.getApplicationHomeDir() != null) {
+ tavernaHome = applicationRuntime.getApplicationHomeDir()
+ .getAbsolutePath();
+ }
+ String cacheLoc = tavernaHome;
+ if (cacheLoc == null || cacheLoc.trim().length() == 0)
+ cacheLoc = "";
+ if (!cacheLoc.endsWith(System.getProperty("file.separator")))
+ cacheLoc += File.separator;
+
+ central = new CentralDigestCachedImpl(this.registryEndpoint,
+ this.registryNamespace, cacheLoc + CACHE_NAME);
+
+ } catch (MobyException e) {
+ //
+ log.warn("There was a problem in initializing the caching agent, therefor caching is disabled.",
+ e);
+ }
+ // now we try to speed up the loading of the datatypes ontology
+ try {
+ new GetOntologyThread(central.getRegistryEndpoint()).start();
+ } catch (Exception e) {
+ /* don't care if an exception occurs here ... */
+ }
+ // just call this to ensure that the registry is valid
+ // throws exception if it isnt
+ central.getResourceRefs();
+ }
+
+ /**
+ *
+ * @return an ArrayList of BiomobyActivityItem
+ * @throws MobyException
+ * if something goes wrong
+ */
+ public synchronized ArrayList<BiomobyActivityItem> getServices()
+ throws MobyException {
+ central.updateCache(CentralDigestCachedImpl.CACHE_PART_SERVICES);
+ MobyService[] services = central.getServices();
+ SortedMap<String, SortedSet<MobyService>> map = new TreeMap<String, SortedSet<MobyService>>();
+ for (MobyService service : services) {
+ String authority = service.getAuthority();
+ SortedSet<MobyService> set;
+ if (map.containsKey(authority)) {
+ set = map.remove(authority);
+ set.add(service);
+ map.put(authority, set);
+ } else {
+ set = new TreeSet<MobyService>(new Comparator<MobyService>() {
+ public int compare(MobyService o1, MobyService o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ set.add(service);
+ map.put(authority, set);
+ }
+ }
+ ArrayList<BiomobyActivityItem> authorityList = new ArrayList<BiomobyActivityItem>();
+ for (String authority_name : map.keySet()) {
+ for (MobyService service : map.get(authority_name)) {
+ String serviceName = service.getName();
+ // if (service.getStatus() != MobyService.UNCHECKED) {
+ // f.setAlive((service.getStatus() & MobyService.ALIVE) == 2);
+ // }
+ BiomobyActivityItem item = makeActivityItem(registryEndpoint,
+ registryNamespace, authority_name, serviceName);
+ item.setCategory(service.getCategory());
+ item.setServiceType(service.getServiceType() == null ? "Service"
+ : service.getServiceType().getName());
+ authorityList.add(item);
+ }
+ }
+ return authorityList;
+
+ }
+
+ private BiomobyActivityItem makeActivityItem(String url, String uri,
+ String authorityName, String serviceName) {
+ BiomobyActivityItem item = new BiomobyActivityItem();
+ item.setAuthorityName(authorityName);
+ item.setServiceName(serviceName);
+ item.setRegistryUrl(url);
+ item.setRegistryUri(uri);
+ return item;
+ }
+
+ public String getRemoteDatatypeRdfUrl() {
+ return remoteDatatypeRdfUrl;
+ }
+
+ public String getRemoteServiceRdfUrl() {
+ return remoteServiceRdfUrl;
+ }
+
+ public static Document loadDocument(InputStream input) throws MobyException {
+ try {
+ DocumentBuilderFactory dbf = (DocumentBuilderFactory) DOCUMENT_BUILDER_FACTORIES
+ .get();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ return (db.parse(input));
+ } catch (Exception e) {
+ throw new MobyException("Problem with reading XML input: "
+ + e.toString(), e);
+ }
+ }
+
+ public static ThreadLocal<DocumentBuilderFactory> DOCUMENT_BUILDER_FACTORIES = new ThreadLocal<DocumentBuilderFactory>() {
+ protected synchronized DocumentBuilderFactory initialValue() {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ return dbf;
+ }
+ };
+
+ public void findServiceDescriptionsAsync(
+ FindServiceDescriptionsCallBack callBack) {
+ try {
+ central.updateCache(CentralDigestCachedImpl.CACHE_PART_SERVICES);
+ } catch (MobyException ex) {
+ callBack.fail("Can't update the Biomoby cache", ex);
+ return;
+ }
+ MobyService[] services;
+ try {
+ services = central.getServices();
+ } catch (MobyException ex) {
+ callBack.fail("Can't get BioMoby services", ex);
+ return;
+ }
+ List<BiomobyServiceDescription> serviceDescriptions = new ArrayList<BiomobyServiceDescription>();
+ for (MobyService service : services) {
+ BiomobyServiceDescription serviceDesc = new BiomobyServiceDescription();
+ serviceDesc.setEndpoint(URI.create(registryEndpoint));
+ serviceDesc.setNamespace(URI.create(registryNamespace));
+ serviceDesc.setAuthorityName(service.getAuthority());
+ serviceDesc.setServiceName(service.getName());
+ serviceDesc.setCategory(service.getCategory());
+ serviceDesc.setDescription(service.getDescription());
+ String lsid = service.getLSID();
+ if (lsid != null && lsid.length() > 0) {
+ serviceDesc.setLSID(URI.create(lsid));
+ }
+ serviceDesc.setEmailContact(service.getEmailContact());
+ serviceDesc.setServiceType(service.getServiceType() == null ? "Service"
+ : service.getServiceType().getName());
+ String signatureURL = service.getSignatureURL();
+ if (signatureURL != null && signatureURL.length() > 0) {
+ serviceDesc.setSignatureURI(URI.create(signatureURL));
+ }
+ serviceDescriptions.add(serviceDesc);
+ }
+ callBack.partialResults(serviceDescriptions);
+ callBack.partialResults(findDatatypeDescriptions());
+ callBack.finished();
+ }
+
+ public List<BiomobyDatatypeDescription> findDatatypeDescriptions() {
+ try {
+ central.updateCache(CentralDigestCachedImpl.CACHE_PART_DATATYPES);
+ } catch (MobyException ex) {
+
+ return new ArrayList<BiomobyDatatypeDescription>();
+ }
+ MobyDataType[] datatypes;
+ try {
+ datatypes = central.getDataTypes();
+ } catch (MobyException ex) {
+
+ return new ArrayList<BiomobyDatatypeDescription>();
+ }
+ List<BiomobyDatatypeDescription> datatypeDescriptions = new ArrayList<BiomobyDatatypeDescription>();
+ for (MobyDataType datatype : datatypes) {
+ BiomobyDatatypeDescription dataDesc = new BiomobyDatatypeDescription();
+ dataDesc.setAuthorityName(datatype.getAuthority());
+ dataDesc.setDatatypeName(datatype.getName());
+ dataDesc.setEmailContact(datatype.getEmailContact());
+ dataDesc.setEndpoint(URI.create(registryEndpoint));
+ dataDesc.setNamespace(URI.create(registryNamespace));
+ dataDesc.setParent(datatype.getParentName());
+ dataDesc.setDescription(datatype.getDescription());
+ String lsid = datatype.getLSID();
+ if (lsid != null && lsid.length() > 0) {
+ try {
+ dataDesc.setLsid(URI.create(lsid));
+ } catch (Exception e) {
+
+ }
+ }
+ ArrayList<String> lineage = new ArrayList<String>();
+ if (datatype.getParent() == null && !datatype.getName().equals("Object")) {
+ lineage.add("Object");
+ lineage.add(datatype.getName());
+ } else
+ for (MobyDataType d : datatype.getLineage())
+ if (!d.getName().equals(datatype.getName()))
+ lineage.add(d.getName());
+ dataDesc.setLineage(lineage.toArray(new String[]{}));
+ datatypeDescriptions.add(dataDesc);
+ }
+ return datatypeDescriptions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/CacheImpl.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/CacheImpl.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/CacheImpl.java
new file mode 100644
index 0000000..37d677e
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/query/CacheImpl.java
@@ -0,0 +1,568 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, Martin Senger, The BioMoby Project
+ */
+
+package net.sf.taverna.t2.activities.biomoby.query;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Comparator;
+
+import org.apache.log4j.Logger;
+import org.biomoby.shared.MobyException;
+
+/**
+ * An implementation of {@link org.biomoby.shared.CentralAll}, allowing to
+ * cache locally results of the cumulative methods so it does not need to access
+ * Moby registry all the time. The other methods of the Central interface do not
+ * use the results of the cached cumulative results (their implementation is
+ * just passed to the parent class).
+ * <p>
+ *
+ * The caching is done in the file system, not in memory, so the results are
+ * permanent (until someone removes the caching directory, or calls
+ * {@link #removeFromCache}).
+ * <p>
+ *
+ * This class can be used also without caching - just instantiate it with
+ * 'cacheDir' set to null in the constructor.
+ * <p>
+ *
+ * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
+ * @version $Id: CacheImpl.java,v 1.2 2008/09/04 13:42:16 sowen70 Exp $
+ */
+
+public class CacheImpl {
+
+ private static Logger log = Logger.getLogger(CacheImpl.class);
+
+ // filename for a list of cached entities
+ protected static final String LIST_FILE = "__L__S__I__D__S__";
+
+ /** An ID used in {@link #removeFromCache} indicating data types part. */
+ public static final String CACHE_PART_DATATYPES = "c1";
+
+ /** An ID used in {@link #removeFromCache} indicating services part. */
+ public static final String CACHE_PART_SERVICES = "c2";
+
+ public static final String CACHE_PROP_NAME = "cache-name";
+
+ public static final String CACHE_PROP_COUNT = "cache-count";
+
+ public static final String CACHE_PROP_OLDEST = "cache-oldest";
+
+ public static final String CACHE_PROP_YOUNGEST = "cache-youngest";
+
+ public static final String CACHE_PROP_SIZE = "cache-size";
+
+ public static final String CACHE_PROP_LOCATION = "cache-loc";
+
+ // DEFAULT registry
+ private String MOBYCENTRAL_REGISTRY_URL = "http://moby.ucalgary.ca/moby/MOBY-Central.pl";
+
+ // Default Endpoint
+ private String MOBYCENTRAL_REGISTRY_URI = "http://moby.ucalgary.ca/MOBY/Central";
+
+ // cache location
+ private String cacheDir; // as defined in the constructor
+
+ protected File dataTypesCache;
+
+ protected File servicesCache;
+
+ public static final String SERVICE_INSTANCE_FILENAME = "SERVICE_INSTANCE.rdf";
+
+ private String serviceInstanceRDFLocation = SERVICE_INSTANCE_FILENAME;
+
+ public static final String DATATYPE_FILENAME = "DATATYPES.rdf";
+
+ private String datatypeRDFLocation = DATATYPE_FILENAME;
+
+ // for optimalization
+ private String fileSeparator;
+
+ /***************************************************************************
+ * Create an instance that will access a default Moby registry and will
+ * cache results in the 'cacheDir' directory.
+ * <p>
+ **************************************************************************/
+ public CacheImpl(String cacheDir) throws MobyException {
+ this(null, null, cacheDir);
+ }
+
+ /***************************************************************************
+ * Create an instance that will access a Moby registry defined by its
+ * 'endpoint' and 'namespace', and will cache results in the 'cacheDir'
+ * directory. Note that the same 'cacheDir' can be safely used for more Moby
+ * registries.
+ * <p>
+ **************************************************************************/
+ public CacheImpl(String endpoint, String namespace, String cacheDir)
+ throws MobyException {
+ if (endpoint != null && !endpoint.trim().equals(""))
+ this.MOBYCENTRAL_REGISTRY_URL = endpoint;
+ if (namespace != null && !namespace.trim().equals(""))
+ this.MOBYCENTRAL_REGISTRY_URI = namespace;
+ fileSeparator = System.getProperty("file.separator");
+ this.cacheDir = cacheDir;
+ initCache();
+ }
+
+ // it makes all necessary directories for cache given in the
+ // constructor (which is now in global 'cacheDir'); it is
+ // separated here because it can be called either from the
+ // constructor, or everytime a cache is going to be used but it is
+ // not there (somebody removed it)
+ protected void initCache() throws MobyException {
+ if (cacheDir != null) {
+ File cache = createCacheDir(cacheDir, MOBYCENTRAL_REGISTRY_URL);
+ dataTypesCache = createSubCacheDir(cache, "datatype_rdf");
+ servicesCache = createSubCacheDir(cache, "service_rdf");
+ serviceInstanceRDFLocation = servicesCache.getPath()
+ + fileSeparator + SERVICE_INSTANCE_FILENAME;
+ datatypeRDFLocation = dataTypesCache.getPath() + fileSeparator
+ + DATATYPE_FILENAME;
+ }
+ }
+
+ /***************************************************************************
+ * Return a directory name representing the current cache. This is the same
+ * name as given in constructors.
+ * <p>
+ *
+ * @return current cache directory name
+ **************************************************************************/
+ public String getCacheDir() {
+ return cacheDir;
+ }
+
+ /***************************************************************************
+ * Removes object groups from the cache. If 'id' is null it removes the
+ * whole cache (for that Moby registry this instance was initiated for).
+ * Otherwise 'id' indicates which part of the cache that will be removed.
+ * <p>
+ *
+ * @param id
+ * should be either null, or one of the following:
+ * {@link #CACHE_PART_DATATYPES}, {@link #CACHE_PART_SERVICES},
+ * {@link #CACHE_PART_SERVICETYPES}, and {@link
+ * #CACHE_PART_NAMESPACES}.
+ **************************************************************************/
+ public void removeFromCache(String id) {
+ try {
+ if (cacheDir != null) {
+ String[] parts = null;
+ if (id == null)
+ parts = new String[] { "datatype_rdf", "service_rdf" };
+ else if (id.equals(CACHE_PART_SERVICES))
+ parts = new String[] { "service_rdf" };
+ else if (id.equals(CACHE_PART_DATATYPES))
+ parts = new String[] { "datatype_rdf" };
+ if (parts != null) {
+ removeCacheDir(cacheDir, MOBYCENTRAL_REGISTRY_URL, parts);
+ }
+ }
+ } catch (MobyException e) {
+ log.error("Removing cache failed: " + e.getMessage());
+ }
+ }
+
+ /**
+ * Create a cache directory from 'cacheDirectory' and 'registryId' if it
+ * does not exist yet. Make sure that it is writable. Return a File
+ * representing created directory.
+ *
+ * 'registryId' (which may be null) denotes what registry this cache is
+ * going to be created for. If null, an endpoint of a default Moby registry
+ * is used.
+ */
+ protected File createCacheDir(String cacheDirectory, String registryId)
+ throws MobyException {
+ if (registryId == null || registryId.equals(""))
+ registryId = MOBYCENTRAL_REGISTRY_URL;
+ File cache = new File(cacheDirectory + fileSeparator
+ + clean(registryId));
+ try {
+ if (!cache.exists())
+ if (!cache.mkdirs())
+ throw new MobyException("Cannot create '"
+ + cache.getAbsolutePath() + "'.");
+ if (!cache.isDirectory())
+ throw new MobyException("Cache location '"
+ + cache.getAbsolutePath()
+ + "' exists but it is not a directory.");
+ if (!cache.canWrite())
+ throw new MobyException("Cache location '"
+ + cache.getAbsolutePath() + "' is not writable for me.");
+ return cache;
+ } catch (SecurityException e) {
+ throw new MobyException("Cannot handle cache location '"
+ + cache.getAbsolutePath() + "'. " + e.toString());
+ }
+ }
+
+ /**
+ * Remove cache and all (but given in 'subCacheDirNames') its
+ * subdirectories.
+ */
+ protected void removeCacheDir(String cacheDirectory, String registryId,
+ String[] subCacheDirNames) throws MobyException {
+ if (registryId == null || registryId.equals(""))
+ registryId = MOBYCENTRAL_REGISTRY_URL;
+ File cache = new File(cacheDirectory + fileSeparator
+ + clean(registryId));
+ try {
+ if (!cache.exists())
+ return;
+ if (!cache.isDirectory())
+ throw new MobyException("Cache location '"
+ + cache.getAbsolutePath()
+ + "' exists but it is not a directory.");
+ if (!cache.canWrite())
+ throw new MobyException("Cache location '"
+ + cache.getAbsolutePath() + "' is not writable for me.");
+ for (int i = 0; i < subCacheDirNames.length; i++) {
+ File cacheSubDir = new File(cache.getAbsolutePath()
+ + fileSeparator + clean(subCacheDirNames[i]));
+ File[] files = cacheSubDir.listFiles();
+ for (int f = 0; f < files.length; f++) {
+ if (files[f].isDirectory())
+ throw new MobyException("Found a directory '"
+ + files[f].getAbsolutePath()
+ + "' where no directory should be");
+ if (!files[f].delete())
+ log.error("Can't delete file '" + files[f] + "'.");
+ }
+ cacheSubDir.delete();
+ }
+ cache.delete();
+
+ } catch (SecurityException e) {
+ throw new MobyException("Cannot handle cache location '"
+ + cache.getAbsolutePath() + "'. " + e.toString());
+ }
+ }
+
+ //
+ protected File createSubCacheDir(File mainCache, String subCacheDirName)
+ throws MobyException {
+ File cache = new File(mainCache.getAbsolutePath() + fileSeparator
+ + clean(subCacheDirName));
+ try {
+ if (!cache.exists())
+ if (!cache.mkdirs())
+ throw new MobyException("Cannot create '"
+ + cache.getAbsolutePath() + "'.");
+ return cache;
+ } catch (SecurityException e) {
+ throw new MobyException("Cannot handle cache location '"
+ + cache.getAbsolutePath() + "'. " + e.toString());
+ }
+ }
+
+ /***************************************************************************
+ * Replace non digit/letter characters in 'toBeCleaned' by their numeric
+ * value. If there are more such numeric values side by side, put a dot
+ * between them. Return the cleaned string.
+ **************************************************************************/
+ protected static String clean(String toBeCleaned) {
+
+ char[] chars = toBeCleaned.toCharArray();
+ int len = chars.length;
+ int i = -1;
+ while (++i < len) {
+ char c = chars[i];
+ if (!Character.isLetterOrDigit(c) && c != '_')
+ break;
+ }
+ if (i < len) {
+ StringBuffer buf = new StringBuffer(len * 2);
+ for (int j = 0; j < i; j++) {
+ buf.append(chars[j]);
+ }
+ boolean lastOneWasDigitalized = false;
+ while (i < len) {
+ char c = chars[i];
+ if (Character.isLetterOrDigit(c) || c == '_') {
+ buf.append(c);
+ lastOneWasDigitalized = false;
+ } else {
+ if (lastOneWasDigitalized)
+ buf.append('.');
+ buf.append((int) c);
+ lastOneWasDigitalized = true;
+ }
+ i++;
+ }
+ return new String(buf);
+ }
+ return toBeCleaned;
+ }
+
+ // create a file and put into it data to be cached
+ protected static void store(File cache, String name, String data)
+ throws MobyException {
+ // File outputFile = new File (cache.getAbsolutePath() + fileSeparator +
+ // clean (name));
+ File outputFile = new File(cache.getAbsolutePath()
+ + System.getProperty("file.separator") + name);
+ try {
+ PrintWriter fileout = new PrintWriter(new BufferedOutputStream(
+ new FileOutputStream(outputFile)));
+ fileout.write(data);
+ fileout.close();
+ } catch (IOException e) {
+ throw new MobyException("Cannot write to '"
+ + outputFile.getAbsolutePath() + ". " + e.toString());
+ }
+ }
+
+ // create a file from a url
+ protected void storeURL(File cache, String name, String url)
+ throws MobyException {
+ File outputFile = new File(cache.getAbsolutePath() + fileSeparator
+ + name);
+ try {
+ StringBuffer sb = new StringBuffer();
+ String newline = System.getProperty("line.separator");
+ HttpURLConnection urlConnection = null;
+
+ URL rdf_url = new URL(url);
+ urlConnection = (HttpURLConnection) rdf_url.openConnection();
+ urlConnection.setDefaultUseCaches(false);
+ urlConnection.setUseCaches(false);
+ urlConnection.setRequestProperty ( "User-agent", "Taverna_BioMOBY/1.5");
+ urlConnection.setConnectTimeout(1000*60*5);
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(
+ urlConnection.getInputStream()));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null)
+ sb.append(inputLine + newline);
+ in.close();
+
+ PrintWriter fileout = new PrintWriter(new BufferedOutputStream(
+ new FileOutputStream(outputFile)));
+ fileout.write(sb.toString());
+ fileout.close();
+ } catch (ConnectException e) {
+ throw new MobyException("Cannot read from url '"
+ + url + "'. " + e.toString());
+ } catch (IOException e) {
+ throw new MobyException("Cannot write to '"
+ + outputFile.getAbsolutePath() + "'. " + e.toString());
+ } catch (Exception e) {
+ throw new MobyException("Unexpected Exception caught: " + e.toString());
+ }
+ }
+
+ // remove a file from a cache
+ protected void remove(File cache, String name) {
+ File file = new File(cache, name);
+ // do not throw here an exception because a missing file
+ // can be a legitimate status (e.g. for LIST_FILE when we
+ // are updating)
+ file.delete();
+ }
+
+ /***************************************************************************
+ * Read a cached file
+ **************************************************************************/
+ protected static String load(File file) throws MobyException {
+ try {
+ StringBuffer buf = new StringBuffer();
+ BufferedReader in = new BufferedReader(new FileReader(file));
+ char[] buffer = new char[1024];
+ int charsRead;
+
+ while ((charsRead = in.read(buffer, 0, 1024)) != -1) {
+ buf.append(buffer, 0, charsRead);
+ }
+
+ return new String(buf);
+
+ } catch (Throwable e) { // be prepare for "out-of-memory" error
+ throw new MobyException("Serious error when reading from cache. "
+ + e.toString());
+
+ }
+ }
+
+ /***************************************************************************
+ * Is the given cache empty (meaning: cache directory does not exist, is
+ * empty, or contains only files to be ignored)?
+ **************************************************************************/
+ protected boolean isCacheEmpty(File cache) throws MobyException {
+ if (cache == null)
+ return true;
+ String[] list = cache.list();
+ if (list == null || list.length == 0)
+ return true;
+ for (int i = 0; i < list.length; i++) {
+ if (!ignoredForEmptiness(new File(list[i])))
+ return false;
+ }
+ return true;
+ }
+
+ /***************************************************************************
+ * A LIST_FILE is a TOC of a cache object (each cache part has its own
+ * LIST_FILE). Read it and return it. If it does not exist, return null.
+ **************************************************************************/
+ protected static String getListFile(File cache) throws MobyException {
+ File listFile = new File(cache, LIST_FILE);
+ if (!listFile.exists())
+ return null;
+ return load(listFile);
+ }
+
+ /***************************************************************************
+ * A LIST_FILE is a TOC of a cache object (each cache part has its own
+ * LIST_FILE). Read it and return it. If it does not exist, return null.
+ **************************************************************************/
+ protected static void storeListFile(File cache, String data)
+ throws MobyException {
+ CacheImpl.store(cache, LIST_FILE, data);
+ }
+
+ /***************************************************************************
+ * Return a comparator for Files that compares in case-insensitive way.
+ **************************************************************************/
+ protected static Comparator getFileComparator() {
+ return new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return o1.toString().compareToIgnoreCase(o2.toString());
+ }
+ };
+ }
+
+ /***************************************************************************
+ * Some file (when being read from a cache directory) are ignored.
+ **************************************************************************/
+ protected static boolean ignored(File file) {
+ String path = file.getPath();
+ return path.endsWith("~") || path.endsWith(LIST_FILE);
+ }
+
+ /***************************************************************************
+ * Some file (when a cache is being tested fir emptyness) are ignored.
+ **************************************************************************/
+ protected static boolean ignoredForEmptiness(File file) {
+ String path = file.getPath();
+ return path.endsWith("~");
+ }
+
+ /***************************************************************************
+ *
+ **************************************************************************/
+ protected static String MSG_CACHE_NOT_DIR(File cache) {
+ return "Surprisingly, '" + cache.getAbsolutePath()
+ + "' is not a directory. Strange...";
+ }
+
+ /***************************************************************************
+ *
+ **************************************************************************/
+ protected static String MSG_CACHE_BAD_FILE(File file, Exception e) {
+ return "Ignoring '" + file.getPath()
+ + "'. It should not be in the cache directory:"
+ + e.getMessage();
+ }
+
+ /***************************************************************************
+ * Return age of the current (whole) cache in millis from the beginning of
+ * the Epoch; or -1 if cache is empty, or the age is unknown.
+ * <p>
+ *
+ * @return the cache age which is taken as the oldest (but filled) cache
+ * part (part is considered e.g. 'services', or 'data types', not
+ * their individual entities)
+ **************************************************************************/
+ public long getCacheAge() {
+ try {
+ long dataTypesCacheAge = (isCacheEmpty(dataTypesCache) ? Long.MAX_VALUE
+ : dataTypesCache.lastModified());
+ long servicesCacheAge = (isCacheEmpty(servicesCache) ? Long.MAX_VALUE
+ : servicesCache.lastModified());
+ long age = Math.min(dataTypesCacheAge, servicesCacheAge);
+ return (age == Long.MAX_VALUE ? -1 : age);
+ } catch (MobyException e) {
+ return -1;
+ }
+ }
+
+ /**
+ * @return the serviceInstanceRDFLocation
+ */
+ public String getServiceInstanceRDFLocation() {
+ return serviceInstanceRDFLocation;
+ }
+
+ /**
+ * @param serviceInstanceRDFLocation
+ * the serviceInstanceRDFLocation to set
+ */
+ public void setServiceInstanceRDFLocation(String serviceInstanceRDFLocation) {
+ this.serviceInstanceRDFLocation = serviceInstanceRDFLocation;
+ }
+
+ /**
+ * @return the mOBYCENTRAL_REGISTRY_URI
+ */
+ public String getMOBYCENTRAL_REGISTRY_URI() {
+ return MOBYCENTRAL_REGISTRY_URI;
+ }
+
+ /**
+ * @param mobycentral_registry_uri
+ * the mOBYCENTRAL_REGISTRY_URI to set
+ */
+ public void setMOBYCENTRAL_REGISTRY_URI(String mobycentral_registry_uri) {
+ MOBYCENTRAL_REGISTRY_URI = mobycentral_registry_uri;
+ }
+
+ /**
+ * @return the MOBYCENTRAL_REGISTRY_URL
+ */
+ public String getMOBYCENTRAL_REGISTRY_URL() {
+ return MOBYCENTRAL_REGISTRY_URL;
+ }
+
+ /**
+ * @param mobycentral_registry_url
+ * the MOBYCENTRAL_REGISTRY_URL to set
+ */
+ public void setMOBYCENTRAL_REGISTRY_URL(String mobycentral_registry_url) {
+ MOBYCENTRAL_REGISTRY_URL = mobycentral_registry_url;
+ }
+
+ /**
+ * @return the datatypeRDFLocation
+ */
+ public String getDatatypeRDFLocation() {
+ return datatypeRDFLocation;
+ }
+
+ /**
+ * @param datatypeRDFLocation the datatypeRDFLocation to set
+ */
+ public void setDatatypeRDFLocation(String datatypeRDFLocation) {
+ this.datatypeRDFLocation = datatypeRDFLocation;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceDescription.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceDescription.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceDescription.java
new file mode 100644
index 0000000..f327e96
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceDescription.java
@@ -0,0 +1,137 @@
+package net.sf.taverna.t2.activities.biomoby.servicedescriptions;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyActivityIcon;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+public class BiomobyServiceDescription extends
+ ServiceDescription<BiomobyActivityConfigurationBean> {
+
+ private String authorityName;
+ private String category;
+ private String emailContact;
+ private URI endpoint;
+
+ private URI lsid;
+
+ private URI namespace;
+ private String serviceName;
+ private String serviceType;
+ private URI signatureURI;
+
+ @Override
+ public Class<? extends Activity<BiomobyActivityConfigurationBean>> getActivityClass() {
+ return BiomobyActivity.class;
+ }
+
+ @Override
+ public BiomobyActivityConfigurationBean getActivityConfiguration() {
+ BiomobyActivityConfigurationBean bean = new BiomobyActivityConfigurationBean();
+ bean.setAuthorityName(getAuthorityName());
+ bean.setServiceName(getServiceName());
+ bean.setMobyEndpoint(getEndpoint().toASCIIString());
+ return bean;
+ }
+
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public String getEmailContact() {
+ return emailContact;
+ }
+
+ public URI getEndpoint() {
+ return endpoint;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return BiomobyActivityIcon.getBiomobyIcon();
+ }
+
+ public URI getLSID() {
+ return lsid;
+ }
+
+ @Override
+ public String getName() {
+ return getServiceName();
+ }
+
+ public URI getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public List<String> getPath() {
+ return Arrays.asList("Biomoby @ " + getEndpoint(), getServiceType(), getAuthorityName());
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public URI getSignatureURI() {
+ return signatureURI;
+ }
+
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public void setEmailContact(String emailContact) {
+ this.emailContact = emailContact;
+ }
+
+ public void setEndpoint(URI endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public void setLSID(URI lsid) {
+ this.lsid = lsid;
+ }
+
+ public void setNamespace(URI namespace) {
+ this.namespace = namespace;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public void setSignatureURI(URI signatureURI) {
+ this.signatureURI = signatureURI;
+ }
+
+ @Override
+ protected List<Object> getIdentifyingData() {
+ return Arrays.<Object>asList(getNamespace(), getEndpoint(), getAuthorityName(), getServiceName());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProvider.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProvider.java
new file mode 100644
index 0000000..a80c5fb
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProvider.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.servicedescriptions;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyActivityIcon;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyQueryHelper;
+import net.sf.taverna.t2.activities.biomoby.ui.AddBiomobyDialogue;
+import net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
+import net.sf.taverna.t2.servicedescriptions.CustomizedConfigurePanelProvider;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.MobyException;
+
+public class BiomobyServiceProvider extends
+ AbstractConfigurableServiceProvider<BiomobyServiceProviderConfig> implements
+ CustomizedConfigurePanelProvider<BiomobyServiceProviderConfig> {
+
+ private static final URI providerId = URI
+ .create("http://taverna.sf.net/2010/service-provider/biomoby");
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public BiomobyServiceProvider() {
+ super(new BiomobyServiceProviderConfig());
+ }
+
+ public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
+ try {
+ // constructor throws exception if it cannot communicate
+ // with the registry
+ BiomobyQueryHelper helper = new BiomobyQueryHelper(getConfiguration().getEndpoint()
+ .toASCIIString(), getConfiguration().getNamespace().toASCIIString());
+ helper.findServiceDescriptionsAsync(callBack);
+ } catch (MobyException ex) {
+ callBack.fail("Could not connect to Biomoby endpoint "
+ + getConfiguration().getEndpoint(), ex);
+ }
+ }
+
+ @Override
+ public List<BiomobyServiceProviderConfig> getDefaultConfigurations() {
+
+ List<BiomobyServiceProviderConfig> defaults = new ArrayList<BiomobyServiceProviderConfig>();
+
+ // If defaults have failed to load from a configuration file then load them here.
+ if (!serviceDescriptionRegistry.isDefaultSystemConfigurableProvidersLoaded()) {
+ defaults.add(new BiomobyServiceProviderConfig(CentralImpl.DEFAULT_ENDPOINT,
+ CentralImpl.DEFAULT_NAMESPACE));
+ } // else return an empty list
+
+ return defaults;
+ }
+
+ public String getName() {
+ return "Biomoby service";
+ }
+
+ public Icon getIcon() {
+ return BiomobyActivityIcon.getBiomobyIcon();
+ }
+
+ @Override
+ public String toString() {
+ return getName() + " " + getConfiguration().getEndpoint();
+ }
+
+ @SuppressWarnings("serial")
+ public void createCustomizedConfigurePanel(
+ final CustomizedConfigureCallBack<BiomobyServiceProviderConfig> callBack) {
+ AddBiomobyDialogue addBiomobyDialogue = new AddBiomobyDialogue() {
+ @Override
+ protected void addRegistry(String registryEndpoint, String registryURI) {
+ BiomobyServiceProviderConfig providerConfig = new BiomobyServiceProviderConfig(
+ registryEndpoint, registryURI);
+ callBack.newProviderConfiguration(providerConfig);
+ }
+ };
+ addBiomobyDialogue.setVisible(true);
+ }
+
+ @Override
+ protected List<? extends Object> getIdentifyingData() {
+ List<String> result;
+ result = Arrays.asList(getConfiguration().getEndpoint().toString());
+ return result;
+ }
+
+ public String getId() {
+ return providerId.toString();
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProviderConfig.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProviderConfig.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProviderConfig.java
new file mode 100644
index 0000000..3f568c7
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/servicedescriptions/BiomobyServiceProviderConfig.java
@@ -0,0 +1,37 @@
+package net.sf.taverna.t2.activities.biomoby.servicedescriptions;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.lang.beans.PropertyAnnotated;
+
+public class BiomobyServiceProviderConfig extends PropertyAnnotated {
+
+ private URI endpoint;
+
+ private URI namespace;
+
+ public BiomobyServiceProviderConfig() {
+ }
+
+ public BiomobyServiceProviderConfig(String endpoint, String namespace) {
+ this.endpoint = URI.create(endpoint.trim());
+ this.namespace = URI.create(namespace.trim());
+ }
+
+ public URI getEndpoint() {
+ return endpoint;
+ }
+
+ public URI getNamespace() {
+ return namespace;
+ }
+
+ public void setEndpoint(URI endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public void setNamespace(URI namespace) {
+ this.namespace = namespace;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/AddBiomobyDialogue.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/AddBiomobyDialogue.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/AddBiomobyDialogue.java
new file mode 100644
index 0000000..99b82f9
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/AddBiomobyDialogue.java
@@ -0,0 +1,94 @@
+package net.sf.taverna.t2.activities.biomoby.ui;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+
+import net.sf.taverna.t2.activities.biomoby.actions.BiomobyScavengerDialog;
+import net.sf.taverna.t2.workbench.MainWindow;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+
+@SuppressWarnings("serial")
+public abstract class AddBiomobyDialogue extends HelpEnabledDialog {
+
+ @SuppressWarnings("unused")
+ private static Logger logger = Logger.getLogger(AddBiomobyDialogue.class);
+
+ private String endpoint = CentralImpl.DEFAULT_ENDPOINT;
+
+ private String uri = CentralImpl.DEFAULT_NAMESPACE;
+
+ public AddBiomobyDialogue() {
+ super(MainWindow.getMainWindow(), "Add BioMoby Registry", true, null);
+ initialize();
+ setLocationRelativeTo(getParent());
+ }
+ public void initialize() {
+ final BiomobyScavengerDialog msp = new BiomobyScavengerDialog();
+ getContentPane().add(msp);
+ JButton accept = new JButton(new OKAction(msp));
+ JButton cancel = new JButton(new CancelAction());
+ msp.add(accept);
+ msp.add(cancel);
+ setResizable(false);
+ getContentPane().add(msp);
+ setLocationRelativeTo(null);
+ pack();
+ }
+
+ protected abstract void addRegistry(String registryEndpoint,
+ String registryURI);
+
+ public class CancelAction extends AbstractAction {
+ public CancelAction() {
+ super("Cancel");
+ }
+
+ public void actionPerformed(ActionEvent ae2) {
+ if (isVisible()) {
+ setVisible(false);
+ dispose();
+ }
+ }
+ }
+
+ public class OKAction extends AbstractAction {
+ private final BiomobyScavengerDialog scavengerDialogue;
+
+ private OKAction(BiomobyScavengerDialog msp) {
+ super("OK");
+ this.scavengerDialogue = msp;
+ }
+
+ public void actionPerformed(ActionEvent ae2) {
+ if (isVisible()) {
+ String registryEndpoint = "";
+ String registryNamespace = "";
+
+ if (scavengerDialogue.getRegistryEndpoint().equals("")) {
+ registryEndpoint = endpoint;
+ } else {
+ registryEndpoint = scavengerDialogue.getRegistryEndpoint();
+ }
+
+ if (scavengerDialogue.getRegistryEndpoint().equals("")) {
+ registryNamespace = uri;
+ } else {
+ registryNamespace = scavengerDialogue.getRegistryURI();
+ }
+
+ try {
+ addRegistry(registryEndpoint.trim(), registryNamespace.trim());
+ } finally {
+ setVisible(false);
+ dispose();
+ }
+ }
+ }
+ }
+
+}
[08/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyObjectActionHelper.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyObjectActionHelper.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyObjectActionHelper.java
new file mode 100644
index 0000000..9ff9d67
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyObjectActionHelper.java
@@ -0,0 +1,787 @@
+/*
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JProgressBar;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JTree;
+import javax.swing.ToolTipManager;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.MutableTreeNode;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.edits.AddBiomobyConsumingServiceEdit;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyData;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.MobyPrimaryDataSet;
+import org.biomoby.shared.MobyPrimaryDataSimple;
+import org.biomoby.shared.MobyService;
+import org.biomoby.shared.data.MobyDataInstance;
+import org.biomoby.shared.data.MobyDataObject;
+import org.biomoby.shared.data.MobyDataObjectSet;
+
+public class BiomobyObjectActionHelper {
+
+ private static Logger logger = Logger
+ .getLogger(BiomobyObjectActionHelper.class);
+
+ private boolean searchParentTypes = false;
+
+ private OutputPort outputPort = null;
+
+ private MobyNamespace[] namespaces = null;
+
+ private EditManager editManager;
+
+ private final FileManager fileManager;
+
+ public BiomobyObjectActionHelper(boolean searchParentTypes, EditManager editManager, FileManager fileManager) {
+ super();
+ this.searchParentTypes = searchParentTypes;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ public BiomobyObjectActionHelper(OutputPort outputPort, boolean searchParentTypes, EditManager editManager, FileManager fileManager) {
+ super();
+ this.searchParentTypes = searchParentTypes;
+ this.outputPort = outputPort;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ public BiomobyObjectActionHelper(EditManager editManager, FileManager fileManager) {
+ super();
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ private class Worker extends Thread {
+ private BiomobyObjectActivity activity;
+
+ private BiomobyObjectActionHelper action;
+
+ private JPanel panel = new JPanel(new BorderLayout());
+
+ private JPanel namespacePanel = new JPanel(new BorderLayout());
+
+ private JProgressBar bar = new JProgressBar();
+
+ private JTree namespaceList = null;
+
+ public Worker(BiomobyObjectActivity activity, BiomobyObjectActionHelper object) {
+ super("Biomoby object action worker");
+ this.activity = activity;
+ this.action = object;
+ }
+
+ /*
+ * method to show the progress bar
+ */
+ private void setUpProgressBar(String text) {
+ bar = new JProgressBar();
+ bar.setIndeterminate(true);
+ bar.setValue(0);
+ bar.setStringPainted(true);
+ bar.setVisible(true);
+ bar.setString(text);
+ if (panel != null){
+ panel.add(bar, BorderLayout.PAGE_END);
+ panel.updateUI();
+ }
+ }
+
+ private void takeDownProgressBar() {
+ if (panel != null) {
+ panel.remove(bar);
+ panel.updateUI();
+ }
+
+ }
+
+ public JPanel getPanel() {
+ return this.panel;
+ }
+
+ public void run() {
+ Central central = activity.getCentral();
+ // ask if we should restrict query by namespace
+ // only do this if we dont have an output port
+ if (action.outputPort == null) {
+ if (JOptionPane.YES_OPTION ==
+ JOptionPane.showConfirmDialog(null, "Would you like to restrict your search by based upon a namespace?\n" +
+ "This can allow you to find only those services that operate on a specific kind of data.",
+ "Restrict query space", JOptionPane.YES_NO_OPTION)) {
+ // create a JList chooser with a done button here
+ setUpProgressBar("Getting namespaces list");
+ try {
+ namespacePanel = new JPanel(new BorderLayout());
+ createNamespaceList(central.getFullNamespaces());
+ JButton button = new JButton("Done");
+ button.addActionListener(new ActionListener(){
+ @SuppressWarnings("unchecked")
+ public void actionPerformed(
+ ActionEvent e) {
+ ArrayList<MobyNamespace> chosen = new ArrayList<MobyNamespace>();
+ TreePath[] paths = namespaceList.getSelectionPaths();
+ for (TreePath p : paths) {
+ if (p.getLastPathComponent() instanceof DefaultMutableTreeNode) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode)p.getLastPathComponent();
+ if (node.isRoot()) {
+ chosen = new ArrayList<MobyNamespace>();
+ break;
+ }
+ if (!node.isLeaf()) {
+ // get the children and add them to chosen
+ Enumeration<DefaultMutableTreeNode> children = node.children();
+ while (children.hasMoreElements() )
+ chosen.add(new MobyNamespace(children.nextElement().toString()));
+ } else {
+ // is a leaf ... add to chosen
+ chosen.add(new MobyNamespace(node.toString()));
+ }
+ }
+ }
+ // set the namespaces that were selected
+ setNamespaces(chosen.toArray(new MobyNamespace[]{}));
+ // get the tree - in a new thread
+ Thread t = new Thread(){
+ public void run() {
+ namespacePanel.setVisible(false);
+ setUpProgressBar("Getting BioMOBY details for " + activity.getConfiguration().getServiceName() + " ...");
+ getSemanticServiceTree();
+ }};
+ t.setDaemon(true);
+ t.start();
+
+ }});
+ // add the list and button to the panel
+ namespacePanel.add(new JScrollPane(namespaceList), BorderLayout.CENTER);
+ namespacePanel.add(button, BorderLayout.PAGE_END);
+ panel.add(namespacePanel, BorderLayout.CENTER);
+ panel.updateUI();
+ } catch (MobyException e) {
+ logger.error("", e);
+ takeDownProgressBar();
+ }
+ takeDownProgressBar();
+ // once done is pressed, insert selected namespace into the namespaces array
+ // show the progress bar
+
+ } else {
+ // start our search
+ setNamespaces(null);
+ setUpProgressBar("Getting BioMOBY details for " + activity.getConfiguration().getServiceName() + " ...");
+ getSemanticServiceTree();
+ }
+ } else {
+ // search only for those services that consume the correct namespaces
+ if (this.action != null && this.action.getNamespaces() != null) {
+ setNamespaces(this.action.getNamespaces());
+ } else {
+ setNamespaces(null);
+ }
+ setUpProgressBar("Getting BioMOBY details for " + activity.getConfiguration().getServiceName() + " ...");
+ // start our search
+ getSemanticServiceTree();
+ }
+
+
+ }
+
+ /**
+ * @param central
+ */
+ private void getSemanticServiceTree() {
+ Central central = activity.getCentral();
+ MobyDataType object = activity.getMobyObject();
+ MobyService template = new MobyService("dummy");
+
+ // strip the lsid portion of the name
+ String name = object.getName();
+ if (name.indexOf(":") > 0) {
+ name = name.substring(name.lastIndexOf(":") + 1);
+ }
+ // initialize a data object to pass into the service template
+ Registry mRegistry = new Registry(central.getRegistryEndpoint(),central.getRegistryEndpoint(),"http://domain.com/MOBY/Central");
+ MobyDataObject data = new MobyDataObject("", mRegistry);
+ data.setDataType(new MobyDataType(name));
+ data.setXmlMode(MobyDataInstance.CENTRAL_XML_MODE);
+ if (action.namespaces != null)
+ data.setNamespaces(action.namespaces);
+ // create the nodes for the tree
+ MutableTreeNode parent = new DefaultMutableTreeNode(name);
+ MutableTreeNode inputNode = new DefaultMutableTreeNode("Feeds into");
+ MutableTreeNode outputNode = new DefaultMutableTreeNode("Produced by");
+
+ // what services does this object feed into?
+ template.setInputs(new MobyData[] { data });
+ template.setCategory("");
+ MobyService[] services = null;
+ Set<MobyService> theServices = new TreeSet<MobyService>();
+ try {
+ services = central.findService(template, null, true, action.searchParentTypes);
+
+ theServices.addAll(Arrays.asList(services));
+ MobyDataObjectSet set = new MobyDataObjectSet("");
+ set.add(data);
+ template.setInputs(null);
+ template.setInputs(new MobyData[]{set});
+ services = central.findService(template, null, true, action.searchParentTypes);
+ theServices.addAll(Arrays.asList(services));
+ } catch (MobyException e) {
+ panel.add(new JTree(new String[] { "Error finding services",
+ "TODO: create a better Error" }), BorderLayout.CENTER);
+ panel.updateUI();
+ return;
+ }
+ createTreeNodes(inputNode, theServices.toArray(new MobyService[]{}));
+ if (inputNode.getChildCount() == 0)
+ inputNode.insert(new DefaultMutableTreeNode(
+ "Object Doesn't Currently Feed Into Any Services"), 0);
+
+ // what services return this object?
+ template = null;
+ template = new MobyService("dummy");
+ template.setCategory("");
+ template.setOutputs(new MobyData[] { data });
+ services = null;
+ theServices = new TreeSet<MobyService>();
+ try {
+ services = central.findService(template, null, true, action.searchParentTypes);
+ theServices.addAll(Arrays.asList(services));
+ MobyDataObjectSet set = new MobyDataObjectSet("");
+ set.add(data);
+ template.setOutputs(null);
+ template.setOutputs(new MobyData[]{set});
+ services = central.findService(template, null, true, action.searchParentTypes);
+ theServices.addAll(Arrays.asList(services));
+ } catch (MobyException e) {
+ panel.add(new JTree(new String[] { "Error finding services",
+ "TODO: create a better Error" }), BorderLayout.CENTER);
+ panel.updateUI();
+ return;
+ }
+ createTreeNodes(outputNode, theServices.toArray(new MobyService[]{}));
+ if (outputNode.getChildCount() == 0)
+ outputNode.insert(new DefaultMutableTreeNode(
+ "Object Isn't Produced By Any Services"), 0);
+ // what kind of object is this?
+
+ // set up the nodes
+ parent.insert(inputNode, 0);
+ parent.insert(outputNode, 1);
+
+ // finally return a tree describing the object
+ final JTree tree = new JTree(parent);
+ tree.setCellRenderer(new BioMobyObjectTreeCustomRenderer());
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ tree.addMouseListener(new MouseListener() {
+ public void mouseClicked(MouseEvent me) {
+ }
+
+ public void mousePressed(MouseEvent me) {
+ mouseReleased(me);
+ }
+
+ public void mouseReleased(MouseEvent me) {
+ if (me.isPopupTrigger()) // right click, show popup menu
+ {
+ TreePath path = tree.getPathForLocation(me.getX(), me.getY());
+ if (path == null)
+ return;
+ if (path.getPathCount() == 4) {
+ if (path.getParentPath().getParentPath().getLastPathComponent()
+ .toString().equals("Feeds into")) {
+
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ if (node == null)
+ return;
+ final String selectedService = node.toString();
+ // ensure that the last selected item is a
+ // service!
+ if (!selectedService.equals(path.getLastPathComponent().toString()))
+ return;
+ final String selectedAuthority = path.getParentPath()
+ .getLastPathComponent().toString();
+ final JPopupMenu menu = new JPopupMenu();
+ // Create and add a menu item for adding to the
+ // item
+ // to the workflow
+ JMenuItem item = new JMenuItem("Add service - " + selectedService
+ + " to the workflow?");
+ item
+ .setIcon(MobyPanel.getIcon("/Add24.gif"));
+ item.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+
+ try {
+ if (outputPort==null) {
+ outputPort = activity.getOutputPorts().iterator().next();
+ }
+ Dataflow currentDataflow = fileManager.getCurrentDataflow();
+ Edit<?> edit = new AddBiomobyConsumingServiceEdit(
+ currentDataflow, activity,
+ selectedService,selectedAuthority,outputPort, editManager.getEdits());
+ editManager.doDataflowEdit(
+ currentDataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("Could not perform action", e);
+ }
+ }
+ });
+ // Create and add a menu item for service
+ // details
+ JMenuItem details = new JMenuItem("Find out about "
+ + selectedService);
+ details
+ .setIcon(MobyPanel.getIcon("/Information24.gif"));
+ details.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ // Create a frame
+ Frame frame = MobyPanel.CreateFrame("A BioMoby Service Description");
+ frame.setSize(getFrameSize());
+ JPanel panel = new MobyPanel(selectedService,"A BioMoby Service Description",
+ createServiceDescription(selectedService,
+ selectedAuthority, activity.getConfiguration().getMobyEndpoint()));
+ frame.add(panel);
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private String createServiceDescription(String selectedService,
+ String selectedAuthority, String endpoint) {
+ StringBuffer sb = new StringBuffer();
+ String newline = System.getProperty("line.separator");
+ MobyService service = new MobyService(selectedService);
+ try {
+ Central central = new CentralImpl(endpoint);
+ service.setAuthority(selectedAuthority);
+ service.setCategory("");
+ MobyService[] services = central.findService(service);
+ if (services == null || services.length != 1) {
+ return "Couldn't retrieve a description on the BioMoby service '"
+ + selectedService + "'";
+ }
+ service = services[0];
+
+ } catch (MobyException e) {
+ logger.error("Could not retrieve a description on the BioMoby service "
+ + selectedService, e);
+ return "Couldn't retrieve a description on the BioMoby service '"
+ + selectedService + "'";
+ }
+ sb.append("Service Contact: " + newline + "\t"
+ + service.getEmailContact() + newline);
+ sb.append("Service Category: " + newline + "\t"
+ + service.getCategory() + newline);
+ sb.append("Service Authority: " + newline + "\t"
+ + service.getAuthority() + newline);
+ sb.append("Service Type: " + newline + "\t"
+ + service.getType() + newline);
+ sb.append("Service Description: " + newline + "\t"
+ + service.getDescription() + newline);
+ sb.append("Location of Service: " + newline + "\t"
+ + service.getURL() + newline);
+ sb.append("Service Signature RDF Document is located at: "
+ + newline + "\t" + service.getSignatureURL()
+ + newline);
+ MobyData[] data = service.getPrimaryInputs();
+ Vector primaryDataSimples = new Vector();
+ Vector primaryDataSets = new Vector();
+ for (int x = 0; x < data.length; x++) {
+ if (data[x] instanceof MobyPrimaryDataSimple)
+ primaryDataSimples.add(data[x]);
+ else
+ primaryDataSets.add(data[x]);
+ }
+ // describe inputs simple then
+ // collections
+ sb.append("Inputs:" + newline);
+ if (primaryDataSimples.size() == 0) {
+ sb.append("\t\tNo Simple input datatypes consumed."
+ + newline);
+ } else {
+ Iterator it = primaryDataSimples.iterator();
+ sb
+ .append("\t\tService consumes the following Simple(s):"
+ + newline);
+ while (it.hasNext()) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) it
+ .next();
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ sb.append("\t\tData type: "
+ + simple.getDataType().getName() + newline);
+ sb.append("\t\t\tArticle name: " + simple.getName()
+ + newline);
+ if (namespaces.length == 0) {
+ sb.append("\t\t\tValid Namespaces: ANY"
+ + newline);
+ } else {
+ sb.append("\t\t\tValid Namespaces: ");
+ for (int x = 0; x < namespaces.length; x++)
+ sb.append(namespaces[x].getName() + " ");
+ sb.append(newline);
+ }
+ }
+ }
+ if (primaryDataSets.size() == 0) {
+ sb.append(newline
+ + "\t\tNo Collection input datatypes consumed."
+ + newline);
+ } else {
+ Iterator it = primaryDataSets.iterator();
+ sb
+ .append(newline
+ + "\t\tService consumes the following collection(s) of datatypes:"
+ + newline);
+ while (it.hasNext()) {
+ MobyPrimaryDataSet set = (MobyPrimaryDataSet) it
+ .next();
+ MobyPrimaryDataSimple simple = null;
+ sb.append("\t\tCollection Name:" + set.getName()
+ + newline);
+ MobyPrimaryDataSimple[] simples = set.getElements();
+ for (int i = 0; i < simples.length; i++) {
+ simple = simples[i];
+ MobyNamespace[] namespaces = simple
+ .getNamespaces();
+ // iterate through set and
+ // do
+ // the following
+ sb.append("\t\tData type: "
+ + simple.getDataType().getName()
+ + newline);
+ sb.append("\t\t\tArticle name: "
+ + simple.getName() + newline);
+ if (namespaces.length == 0) {
+ sb.append("\t\t\tValid Namespaces: ANY"
+ + newline);
+ } else {
+ sb.append("\t\t\tValid Namespaces: ");
+ for (int x = 0; x < namespaces.length; x++)
+ sb
+ .append(namespaces[x].getName()
+ + " ");
+ sb.append(newline);
+ }
+ }
+ }
+ }
+ // describe secondary inputs
+ // describe outputs simple then
+ // collections
+ data = service.getPrimaryOutputs();
+ primaryDataSimples = new Vector();
+ primaryDataSets = new Vector();
+ for (int x = 0; x < data.length; x++) {
+ if (data[x] instanceof MobyPrimaryDataSimple)
+ primaryDataSimples.add(data[x]);
+ else
+ primaryDataSets.add(data[x]);
+ }
+ sb.append("Outputs:" + newline);
+ if (primaryDataSimples.size() == 0) {
+ sb.append("\t\tNo Simple output datatypes produced."
+ + newline);
+ } else {
+ Iterator it = primaryDataSimples.iterator();
+ sb
+ .append("\t\tService produces the following Simple(s):"
+ + newline);
+ while (it.hasNext()) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) it
+ .next();
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ sb.append("\t\tData type: "
+ + simple.getDataType().getName() + newline);
+ sb.append("\t\t\tArticle name: " + simple.getName()
+ + newline);
+ if (namespaces.length == 0) {
+ sb.append("\t\t\tValid Namespaces: ANY"
+ + newline);
+ } else {
+ sb.append("\t\t\tValid Namespaces: ");
+ for (int x = 0; x < namespaces.length; x++)
+ sb.append(namespaces[x].getName() + " ");
+ sb.append(newline);
+ }
+ }
+ }
+ if (primaryDataSets.size() == 0) {
+ sb
+ .append(newline
+ + "\t\tNo Collection output datatypes produced."
+ + newline);
+ } else {
+ Iterator it = primaryDataSets.iterator();
+ sb
+ .append(newline
+ + "\t\tService produces the following collection(s) of datatypes:"
+ + newline);
+ while (it.hasNext()) {
+ MobyPrimaryDataSet set = (MobyPrimaryDataSet) it
+ .next();
+ MobyPrimaryDataSimple simple = null;
+ sb.append("\t\tCollection Name:" + set.getName()
+ + newline);
+ MobyPrimaryDataSimple[] simples = set.getElements();
+ for (int i = 0; i < simples.length; i++) {
+ simple = simples[i];
+ MobyNamespace[] namespaces = simple
+ .getNamespaces();
+ // iterate through set and
+ // do
+ // the following
+ sb.append("\t\tData type: "
+ + simple.getDataType().getName()
+ + newline);
+ sb.append("\t\t\tArticle name: "
+ + simple.getName() + newline);
+ if (namespaces.length == 0) {
+ sb.append("\t\t\tValid Namespaces: ANY"
+ + newline);
+ } else {
+ sb.append("\t\t\tValid Namespaces: ");
+ for (int x = 0; x < namespaces.length; x++)
+ sb
+ .append(namespaces[x].getName()
+ + " ");
+ sb.append(newline);
+ }
+ }
+ }
+ }
+ sb.append((service.isAuthoritative()) ? newline
+ + "The service belongs to this author." + newline
+ : newline
+ + "The service was wrapped by it's author."
+ + newline);
+ return sb.toString();
+ }
+ });
+ // add the components to the menus
+ menu.add(new JLabel("Add to workflow ... ", JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item);
+ menu.add(new JSeparator());
+ menu.add(new JLabel("Service Details ... ", JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(details);
+ // show the window
+ menu.show(me.getComponent(), me.getX(), me.getY());
+ }
+ }
+ }
+ }
+
+ public void mouseEntered(MouseEvent me) {
+ }
+
+ public void mouseExited(MouseEvent me) {
+ }
+ });
+ tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ panel.add(new JScrollPane(tree), BorderLayout.CENTER);
+ takeDownProgressBar();
+ }
+
+ private void createNamespaceList(MobyNamespace[] fullNamespaces) {
+ // sort the namespaces alphabetically
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("ANY");
+ // assuming that they increment by one ...
+ TreeMap<String, TreeSet<String>> sorted = new TreeMap<String, TreeSet<String>>();
+ for (MobyNamespace n : fullNamespaces) {
+ String name = n.getName();
+ String key = name.toUpperCase().substring(0, 1);
+ if (sorted.get(key) == null) {
+ sorted.put(key, new TreeSet<String>());
+ }
+ sorted.get(key).add(name);
+ }
+ for (String o : sorted.keySet()) {
+ if (sorted.get(o) == null)
+ continue;
+ TreeSet<String> set = sorted.get(o);
+ String first = set.first().toUpperCase().charAt(0) + "";
+ DefaultMutableTreeNode node = new DefaultMutableTreeNode(first);
+ for (String s : set) {
+ node.add(new DefaultMutableTreeNode(s));
+ }
+ root.add(node);
+ }
+ namespaceList = new JTree(root);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflui.processoractions.AbstractProcessorAction#getComponent(org.embl.ebi.escience.scufl.Processor)
+ */
+ public JComponent getComponent(BiomobyObjectActivity activity) {
+
+ // this was done so that for longer requests, something is shown visually and the user then wont think that nothing happened.
+ Worker worker = new Worker(activity, this);
+ worker.start();
+ return worker.getPanel();
+ }
+
+ /*
+ * method that processes the services returned by findService and adds them
+ * to the TreeNode parentNode, sorted by authority
+ */
+ @SuppressWarnings("unchecked")
+ private void createTreeNodes(MutableTreeNode parentNode, MobyService[] services) {
+ HashMap inputHash;
+ inputHash = new HashMap();
+ for (int x = 0; x < services.length; x++) {
+ DefaultMutableTreeNode authorityNode = null;
+ if (!inputHash.containsKey(services[x].getAuthority())) {
+ authorityNode = new DefaultMutableTreeNode(services[x].getAuthority());
+ } else {
+ authorityNode = (DefaultMutableTreeNode) inputHash.get(services[x].getAuthority());
+ }
+ MobyServiceTreeNode serv = new MobyServiceTreeNode(services[x].getName(), services[x]
+ .getDescription());
+ MutableTreeNode temp = new DefaultMutableTreeNode(serv);
+ DefaultMutableTreeNode objects = new DefaultMutableTreeNode("Produces");
+ // add to this node the MobyObjectTreeNodes that it produces!
+ MobyData[] outputs = services[x].getPrimaryOutputs();
+ for (int i = 0; i < outputs.length; i++) {
+ if (outputs[i] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) outputs[i];
+ StringBuffer sb = new StringBuffer("Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ sb.append(namespaces[j].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append("ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(simple
+ .getDataType().getName()
+ + "('" + simple.getName() + "')", sb.toString());
+ objects.insert(new DefaultMutableTreeNode(mobyObjectTreeNode), objects
+ .getChildCount());
+ } else {
+ // we have a collection
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) outputs[i];
+ DefaultMutableTreeNode collectionNode = new DefaultMutableTreeNode(
+ "Collection('" + collection.getName() + "')");
+ objects.insert(collectionNode, objects.getChildCount());
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int j = 0; j < simples.length; j++) {
+ MobyPrimaryDataSimple simple = simples[j];
+ StringBuffer sb = new StringBuffer("Namespaces used by this object: ");
+ MobyNamespace[] namespaces = simple.getNamespaces();
+ for (int k = 0; k < namespaces.length; k++) {
+ sb.append(namespaces[k].getName() + " ");
+ }
+ if (namespaces.length == 0)
+ sb.append("ANY ");
+ MobyObjectTreeNode mobyObjectTreeNode = new MobyObjectTreeNode(simple
+ .getDataType().getName()
+ + "('" + simple.getName() + "')", sb.toString());
+ collectionNode.insert(new DefaultMutableTreeNode(mobyObjectTreeNode),
+ collectionNode.getChildCount());
+ }
+
+ }
+ }
+
+ temp.insert(objects, temp.getChildCount());
+
+ authorityNode.insert(temp, authorityNode.getChildCount());
+ inputHash.put(services[x].getAuthority(), authorityNode);
+
+ }
+ Set set = inputHash.keySet();
+ SortedSet sortedset = new TreeSet(set);
+ for (Iterator it = sortedset.iterator(); it.hasNext();) {
+ parentNode.insert((DefaultMutableTreeNode) inputHash.get((String) it.next()),
+ parentNode.getChildCount());
+ }
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflui.processoractions.ProcessorActionSPI#getDescription()
+ */
+ public String getDescription() {
+ return "Moby Object Details";
+ }
+
+ /*
+ *
+ */
+ public ImageIcon getIcon() {
+ return MobyPanel.getIcon("/moby_small.gif");
+ }
+
+ /**
+ * returns the frame size as a dimension for the content pane housing this
+ * action
+ */
+ public Dimension getFrameSize() {
+ return new Dimension(450, 450);
+ }
+
+ public void setNamespaces(MobyNamespace[] namespaces) {
+ if (namespaces != null && namespaces.length == 0)
+ this.namespaces = null;
+ else
+ this.namespaces = namespaces;
+ }
+ public MobyNamespace[] getNamespaces() {
+ return this.namespaces == null ? new MobyNamespace[]{} : this.namespaces;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyScavengerDialog.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyScavengerDialog.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyScavengerDialog.java
new file mode 100644
index 0000000..4419bf9
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/BiomobyScavengerDialog.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.biomoby.registry.meta.Registries;
+import org.biomoby.registry.meta.RegistriesList;
+import org.biomoby.shared.MobyException;
+
+import net.sf.taverna.t2.lang.ui.ShadedLabel;
+
+/**
+ * a dialog for helping create scavengers for BioMoby registries that are not
+ * the default registry.
+ *
+ */
+public class BiomobyScavengerDialog extends JPanel {
+
+ private static final String CUSTOM = "Custom";
+ private static final long serialVersionUID = -57047613557546674L;
+ private JTextField registryEndpoint = new JTextField(
+ "http://moby.ucalgary.ca/moby/MOBY-Central.pl");
+ private JTextField registryURI = new JTextField(
+ "http://moby.ucalgary.ca/MOBY/Central");
+
+ /**
+ * Default constructor.
+ *
+ */
+ /**
+ * Default constructor.
+ *
+ */
+ public BiomobyScavengerDialog() {
+ super();
+ GridLayout layout = new GridLayout(5, 2);
+ setLayout(layout);
+
+ registryEndpoint.setEnabled(false);
+ registryURI.setEnabled(false);
+
+ // a combo box showing known registries
+ final Registries regs = RegistriesList.getInstance();
+ List<String> choices = new ArrayList<String>(Arrays.asList(regs.list()));
+ choices.add(CUSTOM);
+
+ JComboBox regList = new JComboBox(choices.toArray());
+ regList.setToolTipText("A selection will fill text fields below");
+ regList.setSelectedItem(Registries.DEFAULT_REGISTRY_SYNONYM);
+ regList.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ String contents = (String) ((JComboBox) e.getSource())
+ .getSelectedItem();
+
+ if (contents.equals(CUSTOM)) {
+ registryEndpoint.setEnabled(true);
+ registryURI.setEnabled(true);
+ return;
+ } else {
+ registryEndpoint.setEnabled(false);
+ registryURI.setEnabled(false);
+ }
+ org.biomoby.registry.meta.Registry theReg = null;
+ try {
+ theReg = regs.get(contents);
+ } catch (MobyException ee) {
+ try {
+ theReg = regs.get(null);
+ } catch (MobyException ee2) {
+
+ }
+ }
+ if (theReg != null) {
+ registryEndpoint.setText(theReg.getEndpoint());
+ registryURI.setText(theReg.getNamespace());
+
+ }
+ }
+ });
+ add(new ShadedLabel("Choose a registry from the list: ",
+ ShadedLabel.BLUE, true));
+ add(regList);
+ add(new ShadedLabel("Or select '" + CUSTOM + "' to enter your own below,", ShadedLabel.BLUE, true));
+ add(new ShadedLabel("", ShadedLabel.BLUE, true));
+ add(new ShadedLabel(
+ "Location (URL) of your BioMoby central registry: ",
+ ShadedLabel.BLUE, true));
+ registryEndpoint
+ .setToolTipText("BioMoby Services will be retrieved from the endpoint that you specify here!");
+ add(registryEndpoint);
+ add(new ShadedLabel(
+ "Namespace (URI) of your BioMoby central registry: ",
+ ShadedLabel.BLUE, true));
+ registryURI
+ .setToolTipText("BioMoby Services will be retrieved from the endpoint/URI that you specify here!");
+ add(registryURI);
+ // add(Box.createHorizontalGlue());add(Box.createHorizontalGlue());
+ setPreferredSize(this.getPreferredSize());
+ setMinimumSize(this.getPreferredSize());
+ setMaximumSize(this.getPreferredSize());
+
+ }
+
+ /**
+ *
+ * @return the string representation of the BioMoby Registry endpoint
+ */
+ public String getRegistryEndpoint() {
+ return registryEndpoint.getText();
+ }
+
+ /**
+ *
+ * @return the string representation of the BioMoby Registry endpoint
+ */
+ public String getRegistryURI() {
+ return registryURI.getText();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectDetailsAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectDetailsAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectDetailsAction.java
new file mode 100644
index 0000000..803fde3
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectDetailsAction.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JDialog;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+@SuppressWarnings("serial")
+public class MobyObjectDetailsAction extends AbstractAction {
+
+ private final BiomobyObjectActivity activity;
+ private final Frame owner;
+ private EditManager editManager;
+
+ private static final String MOBY_OBJECT_DETAILS_ACTION = "Datatype registry query";
+ private final FileManager fileManager;
+
+ public MobyObjectDetailsAction(BiomobyObjectActivity activity, Frame owner, EditManager editManager, FileManager fileManager) {
+ this.activity = activity;
+ this.owner = owner;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ putValue(NAME, MOBY_OBJECT_DETAILS_ACTION);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e) {
+ BiomobyObjectActionHelper helper = new BiomobyObjectActionHelper(editManager, fileManager);
+ Dimension size = helper.getFrameSize();
+
+ Component component = helper.getComponent(activity);
+
+ final JDialog dialog = new HelpEnabledDialog(owner, helper.getDescription(), false, null);
+ dialog.getContentPane().add(component);
+ dialog.pack();
+ // dialog.setTitle(helper.getDescription());
+ dialog.setSize(size);
+ // dialog.setModal(false);
+ dialog.setVisible(true);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectTreeNode.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectTreeNode.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectTreeNode.java
new file mode 100644
index 0000000..f58efc6
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyObjectTreeNode.java
@@ -0,0 +1,50 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import org.biomoby.shared.MobyNamespace;
+
+public class MobyObjectTreeNode {
+
+ // name of the object == node name
+ private String name = "";
+
+ // description of object == tool tip text
+ private String description = "";
+
+ private MobyNamespace[] ns = null;
+ /**
+ *
+ * @param name - the name of the Moby Object
+ * @param description - the description of the Moby Service
+ */
+ public MobyObjectTreeNode(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+ /*
+ * over-ride the toString method in order to print node values
+ * that make sense.
+ */
+ public String toString() {
+ return name;
+ }
+
+ public void setNamespaces(MobyNamespace[] namespaces) {
+ if (namespaces != null && namespaces.length == 0)
+ this.ns = null;
+ else
+ this.ns = namespaces;
+ }
+
+ public MobyNamespace[] getNamespaces() {
+ return this.ns;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyPanel.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyPanel.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyPanel.java
new file mode 100644
index 0000000..a2e0a70
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyPanel.java
@@ -0,0 +1,136 @@
+/*
+ * Created on Sep 9, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.ImageIcon;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import net.sf.taverna.t2.lang.ui.DialogTextArea;
+
+/**
+ * @author Eddie Kawas
+ *
+ *
+ */
+public class MobyPanel extends JPanel {
+
+
+ private static final long serialVersionUID = 1L;
+ private DialogTextArea textArea = null;
+ private String text = "";
+ private String name = "";
+ private JLabel jLabel = new JLabel();
+
+ /**
+ * This is the default constructor
+ */
+ public MobyPanel(String label, String name, String text) {
+ super(new BorderLayout());
+ jLabel.setText(label);
+ this.text = text;
+ this.name = name;
+ initialize();
+ }
+
+ public MobyPanel(String label) {
+ super(new BorderLayout());
+ jLabel.setText(label);
+ initialize();
+ }
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize() {
+ this.setSize(450, 450);
+ jLabel.setHorizontalAlignment(JLabel.CENTER);
+ add(jLabel, BorderLayout.NORTH);
+ add(getTextArea(), BorderLayout.CENTER);
+ }
+
+ /**
+ * This method initializes jTextArea
+ *
+ * @return DialogTextArea
+ */
+ private DialogTextArea getTextArea() {
+ if (textArea == null) {
+ textArea = new DialogTextArea();
+ }
+ textArea.setLineWrap(true);
+ textArea.setWrapStyleWord(true);
+ textArea.setText(this.text);
+ textArea.setEditable(false);
+ textArea.setEnabled(true);
+ textArea.setAutoscrolls(true);
+ textArea.setCaretPosition(0);
+ return textArea;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ if (textArea == null) {
+ textArea = new DialogTextArea(this.text);
+ }
+ textArea.setText(text);
+ }
+
+ /* (non-Javadoc)
+ * @see org.embl.ebi.escience.scuflui.ScuflUIComponent#getIcon()
+ */
+ public ImageIcon getIcon() {
+ return new ImageIcon(MobyPanel.class.getResource("/moby_small.png"));
+ }
+
+ /**
+ *
+ * @param icon a relative path to an icon to get
+ * @return the ImageIcon at icon
+ */
+ public static ImageIcon getIcon(String icon) {
+ return new ImageIcon(MobyPanel.class.getResource(icon));
+ }
+
+ public String getName(){
+ if (name==null) return "";
+ else return name;
+ }
+
+ public void onDisplay() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void onDispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public static Frame CreateFrame(String title) {
+ // Create a frame
+ Frame frame = new Frame(title);
+ // Add a listener for the close event
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent evt) {
+ Frame frame = (Frame)evt.getSource();
+ // Hide the frame
+ frame.setVisible(false);
+ // If the frame is no longer needed, call dispose
+ frame.dispose();
+ }
+ });
+ return frame;
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyParserAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyParserAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyParserAction.java
new file mode 100644
index 0000000..865c1f1
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyParserAction.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Component;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JDialog;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+@SuppressWarnings("serial")
+public class MobyParserAction extends AbstractAction {
+
+ private final BiomobyActivity activity;
+ private final Frame owner;
+ private EditManager editManager;
+ private final FileManager fileManager;
+
+ public MobyParserAction(BiomobyActivity activity, Frame owner, EditManager editManager, FileManager fileManager) {
+ this.activity = activity;
+ this.owner = owner;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ putValue(NAME, "Add Biomoby parser");
+
+ }
+ public void actionPerformed(ActionEvent e) {
+ AddParserActionHelper helper = new AddParserActionHelper(editManager, fileManager);
+ Component component = helper.getComponent(activity);
+
+ final JDialog dialog = new HelpEnabledDialog(owner, helper.getDescription(), false, null);
+ dialog.getContentPane().add(component);
+ dialog.pack();
+// dialog.setSize(helper.getFrameSize());
+ dialog.setTitle(helper.getDescription());
+// dialog.setModal(false);
+ dialog.setVisible(true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceDetailsAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceDetailsAction.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceDetailsAction.java
new file mode 100644
index 0000000..5000986
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceDetailsAction.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.JDialog;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+@SuppressWarnings("serial")
+public class MobyServiceDetailsAction extends AbstractAction {
+
+ private final BiomobyActivity activity;
+ private final Frame owner;
+ private EditManager editManager;
+
+ private static final String MOBY_SERVICE_DETAILS_ACTION = "Browse Biomoby service details";
+ private final FileManager fileManager;
+ public MobyServiceDetailsAction(BiomobyActivity activity, Frame owner, EditManager editManager, FileManager fileManager) {
+ this.activity = activity;
+ this.owner = owner;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ putValue(NAME, MOBY_SERVICE_DETAILS_ACTION);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent e) {
+
+ BiomobyActionHelper helper = new BiomobyActionHelper(editManager, fileManager);
+ Dimension size = helper.getFrameSize();
+
+ Component component = helper.getComponent(activity);
+ final JDialog dialog = new HelpEnabledDialog(owner, helper.getDescription(), false, null);
+
+ dialog.getContentPane().add(component);
+ dialog.pack();
+// dialog.setTitle(helper.getDescription());
+ dialog.setSize(size);
+// dialog.setModal(false);
+ dialog.setVisible(true);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceTreeNode.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceTreeNode.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceTreeNode.java
new file mode 100644
index 0000000..c957a1f
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/MobyServiceTreeNode.java
@@ -0,0 +1,42 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+import java.util.ArrayList;
+
+public class MobyServiceTreeNode {
+
+ // name of the service == node name
+ private String name = "";
+
+ // list of objects that service produces
+ @SuppressWarnings("unused")
+ private ArrayList<MobyObjectTreeNode> mobyObjectTreeNodes = null;
+
+ // description of object == tool tip text
+ private String description = "";
+
+
+ /**
+ *
+ * @param name - the name of the Moby Service
+ * @param description - the description of the Moby Service
+ */
+ public MobyServiceTreeNode(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+ /*
+ * over-ride the toString method in order to print node values
+ * that make sense.
+ */
+ public String toString() {
+ return name;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/PopupThread.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/PopupThread.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/PopupThread.java
new file mode 100644
index 0000000..0c8b9fc
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/PopupThread.java
@@ -0,0 +1,34 @@
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.Component;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+
+
+public class PopupThread extends Thread {
+
+ Object object = null;
+
+ BiomobyObjectActivity objectActivity = null;
+
+ BiomobyObjectActionHelper objectAction = null;
+
+ boolean done = false;
+
+ PopupThread(BiomobyObjectActivity bop, BiomobyObjectActionHelper boa) {
+ super("Biomoby popup");
+ this.objectAction = boa;
+ this.objectActivity = bop;
+ setDaemon(true);
+ }
+
+ public void run() {
+ object = objectAction.getComponent(objectActivity);
+ this.done = true;
+ }
+
+ // call after you check if done!
+ public Component getComponent() {
+ return (Component) object;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/SimpleActionFrame.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/SimpleActionFrame.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/SimpleActionFrame.java
new file mode 100644
index 0000000..a85b50b
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/actions/SimpleActionFrame.java
@@ -0,0 +1,46 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.actions;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+
+import javax.swing.JPanel;
+
+
+/**
+ * This class contains some methods that are useful in creating a consistent JPanel
+ * for displaying information or actions for biomoby services and datatypes.
+ *
+ * @author Edward Kawas
+ * @author Stuart Owen = initial port from T1 to T2
+ *
+ */
+public class SimpleActionFrame extends JPanel {
+
+ private static final long serialVersionUID = -6611234116434482238L;
+
+
+ private String name = "";
+ public SimpleActionFrame(Component c, String name) {
+ super(new BorderLayout());
+ add(c, BorderLayout.CENTER);
+
+ this.name = name;
+ }
+
+
+
+ public String getName() {
+ return name;
+ }
+
+ public void onDisplay() {
+
+ }
+
+
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/datatypedescriptions/BiomobyDatatypeDescription.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/datatypedescriptions/BiomobyDatatypeDescription.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/datatypedescriptions/BiomobyDatatypeDescription.java
new file mode 100644
index 0000000..35df9b8
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/datatypedescriptions/BiomobyDatatypeDescription.java
@@ -0,0 +1,143 @@
+package net.sf.taverna.t2.activities.biomoby.datatypedescriptions;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyObjectActivityIcon;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+public class BiomobyDatatypeDescription extends
+ ServiceDescription<BiomobyObjectActivityConfigurationBean> {
+
+ private String authorityName;
+ private String emailContact;
+ private String datatypeName;
+ private URI lsid;
+ private String parent;
+ private String[] lineage;
+
+ private URI endpoint;
+ private URI namespace;
+
+ @Override
+ public Class<? extends Activity<BiomobyObjectActivityConfigurationBean>> getActivityClass() {
+ return BiomobyObjectActivity.class;
+ }
+
+ @Override
+ public BiomobyObjectActivityConfigurationBean getActivityConfiguration() {
+ BiomobyObjectActivityConfigurationBean bean = new BiomobyObjectActivityConfigurationBean();
+ bean.setAuthorityName(getAuthorityName());
+ bean.setServiceName(getDatatypeName());
+ bean.setMobyEndpoint(getEndpoint().toASCIIString());
+ return bean;
+ }
+
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+ public String getEmailContact() {
+ return emailContact;
+ }
+
+ public void setEmailContact(String emailContact) {
+ this.emailContact = emailContact;
+ }
+
+ public String getDatatypeName() {
+ return datatypeName;
+ }
+
+ public void setDatatypeName(String datatypeName) {
+ this.datatypeName = datatypeName;
+ }
+
+ public URI getLsid() {
+ return lsid;
+ }
+
+ public void setLsid(URI lsid) {
+ this.lsid = lsid;
+ }
+
+ public String getParent() {
+ return parent;
+ }
+
+ public void setParent(String parent) {
+ this.parent = parent;
+ }
+
+ public URI getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(URI endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public URI getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(URI namespace) {
+ this.namespace = namespace;
+ }
+
+ public String[] getLineage() {
+ return lineage;
+ }
+
+ public void setLineage(String[] lineage) {
+ this.lineage = lineage;
+ }
+
+ @Override
+ public String getName() {
+ return getDatatypeName();
+ }
+
+ @Override
+ protected List<Object> getIdentifyingData() {
+ return Arrays.<Object> asList(getNamespace(), getEndpoint(), getAuthorityName(),
+ getDatatypeName());
+ }
+
+ @Override
+ public List<String> getPath() {
+ ArrayList<String> list = new ArrayList<String>();
+ list.add("Biomoby @ " + getEndpoint());
+ list.add("MOBY Objects");
+ list.addAll(Arrays.asList(getLineage()));
+ return list;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return new BiomobyObjectActivityIcon().getIcon(new BiomobyObjectActivity());
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ // public Edit getInsertionEdit(Dataflow dataflow, Processor p, Activity a) {
+ // if (a instanceof BiomobyObjectActivity) {
+ // return new AddUpstreamObjectEdit(dataflow, p, (BiomobyObjectActivity) a);
+ // }
+ // return null;
+ // }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyCollectionDataTypeEdit.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyCollectionDataTypeEdit.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyCollectionDataTypeEdit.java
new file mode 100644
index 0000000..8e02195
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyCollectionDataTypeEdit.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.edits;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edits;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class AddBiomobyCollectionDataTypeEdit extends
+ AddBiomobyDataTypeEdit {
+
+ private final String theCollectionName;
+
+ /**
+ * @param dataflow
+ * @param activity
+ * @param objectName
+ */
+ public AddBiomobyCollectionDataTypeEdit(Dataflow dataflow,
+ BiomobyActivity activity, String objectName, String theCollectionName, Edits edits) {
+ super(dataflow, activity, objectName, edits);
+ this.theCollectionName = theCollectionName;
+ }
+
+ @Override
+ protected String determineInputPortName(String defaultName,String objectName) {
+ return defaultName
+ + "(Collection - '"
+ + (theCollectionName.equals("") ? "MobyCollection"
+ : theCollectionName)
+ + "')";
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyConsumingServiceEdit.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyConsumingServiceEdit.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyConsumingServiceEdit.java
new file mode 100644
index 0000000..e13c208
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyConsumingServiceEdit.java
@@ -0,0 +1,236 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.edits;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.MobyDataType;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.EventForwardingOutputPort;
+import net.sf.taverna.t2.workflowmodel.EventHandlingInputPort;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorOutputPort;
+import net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit;
+import net.sf.taverna.t2.workflowmodel.impl.DataflowImpl;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class AddBiomobyConsumingServiceEdit extends AbstractDataflowEdit {
+
+ private final BiomobyObjectActivity activity;
+ private final String serviceName;
+ private Edits edits;
+ Edit<?> compoundEdit = null;
+ Edit<?> linkEdit = null;
+ private final String authority;
+ private final OutputPort outputPort;
+
+ /**
+ * @param dataflow
+ */
+ public AddBiomobyConsumingServiceEdit(Dataflow dataflow,
+ BiomobyObjectActivity activity, String serviceName,String authority,OutputPort outputPort, Edits edits) {
+ super(dataflow);
+
+ this.activity = activity;
+ this.serviceName = serviceName;
+ this.authority = authority;
+ this.outputPort = outputPort;
+ this.edits = edits;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractEdit#doEditAction(java.lang
+ * .Object)
+ */
+ @Override
+ protected void doEditAction(DataflowImpl dataflow) throws EditException {
+ String defaultName = serviceName;
+ String name = Tools
+ .uniqueProcessorName(defaultName, dataflow);
+
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+
+ net.sf.taverna.t2.workflowmodel.Processor sinkProcessor = edits
+ .createProcessor(name);
+
+ BiomobyActivityConfigurationBean bean = new BiomobyActivityConfigurationBean();
+ bean.setAuthorityName(authority);
+ bean.setServiceName(serviceName);
+ bean.setMobyEndpoint(activity.getConfiguration().getMobyEndpoint());
+ BiomobyActivity boActivity = new BiomobyActivity();
+ editList.add(edits.getConfigureActivityEdit(boActivity, bean));
+
+ editList.add(edits.getDefaultDispatchStackEdit(sinkProcessor));
+
+ Edit<?> addActivityToProcessorEdit = edits.getAddActivityEdit(
+ sinkProcessor, boActivity);
+ editList.add(addActivityToProcessorEdit);
+
+ editList.add(edits.getAddProcessorEdit(dataflow, sinkProcessor));
+
+ compoundEdit = new CompoundEdit(editList);
+ compoundEdit.doEdit();
+
+ net.sf.taverna.t2.workflowmodel.Processor sourceProcessor = Tools.getProcessorsWithActivityOutputPort(dataflow, outputPort).iterator().next();
+
+ List<Edit<?>> linkEditList = new ArrayList<Edit<?>>();
+
+ EventForwardingOutputPort sourcePort = null;
+ //FIXME: there is an assumption here that the processor will contain only 1 activity.
+ if (outputPort != null) {
+ sourcePort = getSourcePort(sourceProcessor, sourceProcessor.getActivityList().get(0), outputPort.getName(), linkEditList);
+ }
+ else {
+ sourcePort = getSourcePort(sourceProcessor, sourceProcessor.getActivityList().get(0), sourceProcessor.getOutputPorts().get(0).getName(), linkEditList);
+ }
+ // get the input port that isnt called 'input'
+ String inputPortName = "";
+ for (ActivityInputPort aip : sinkProcessor.getActivityList().get(0).getInputPorts()) {
+ if (!aip.getName().equalsIgnoreCase("input")) {
+ // try to match the datatype to an input port
+ String dtName = activity.getMobyObject().getName();
+ String sinkDtname = aip.getName();
+ if (sinkDtname.indexOf("(") > 0)
+ sinkDtname = sinkDtname.substring(0, sinkDtname.indexOf("("));
+ // are the datatype names exactly the same?
+ if (dtName.equals(sinkDtname)) {
+ inputPortName = aip.getName();
+ break;
+ }
+ // check for the name in the datatypes lineage
+ MobyDataType sinkDt = MobyDataType.getDataType(dtName,
+ new Registry(
+ activity.getCentral().getRegistryEndpoint(),
+ activity.getCentral().getRegistryEndpoint(),
+ activity.getCentral().getRegistryNamespace())
+ );
+ // check the lineage of the sinkdt for dtname
+ for (MobyDataType lineage : sinkDt.getLineage()) {
+ if (lineage.getName().equals(sinkDtname)) {
+ inputPortName = aip.getName();
+ break;
+ }
+ }
+ // are we done?
+ if (!inputPortName.trim().equals(""))
+ break;
+ }
+ }
+ // if inputPortName is not set, then just pick the first one
+ if (inputPortName.trim().equals("")) {
+ inputPortName = sinkProcessor.getActivityList().get(0).getInputPorts().iterator().next().getName();
+ }
+ EventHandlingInputPort sinkPort = getSinkPort(sinkProcessor, boActivity, inputPortName, linkEditList);
+ if (sinkPort==null) {
+ throw new EditException("No valid input called '"+inputPortName+"' found for Biomoby consuming service");
+ }
+ linkEditList.add(Tools
+ .getCreateAndConnectDatalinkEdit(
+ dataflow,
+ sourcePort, sinkPort, edits));
+ linkEdit = new CompoundEdit(linkEditList);
+ linkEdit.doEdit();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workflowmodel.impl.AbstractEdit#undoEditAction(java
+ * .lang.Object)
+ */
+ @Override
+ protected void undoEditAction(DataflowImpl subjectImpl) {
+ if (linkEdit!=null && linkEdit.isApplied())
+ linkEdit.undo();
+ if (compoundEdit!=null && compoundEdit.isApplied())
+ compoundEdit.undo();
+ }
+
+ private EventHandlingInputPort getSinkPort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ InputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityInputPort(activity, portName);
+ // check if processor port exists
+ EventHandlingInputPort input = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorInputPort(processor, activity, activityPort);
+ if (input == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorInputPort processorInputPort = edits
+ .createProcessorInputPort(processor,
+ activityPort.getName(), activityPort.getDepth());
+ editList.add(edits.getAddProcessorInputPortEdit(processor,
+ processorInputPort));
+ editList.add(edits.getAddActivityInputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ input = processorInputPort;
+ }
+ return input;
+ }
+
+ private EventForwardingOutputPort getSourcePort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ OutputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityOutputPort(activity, portName);
+ // check if processor port exists
+ EventForwardingOutputPort output = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorOutputPort(processor, activity, activityPort);
+ if (output == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorOutputPort processorOutputPort = edits
+ .createProcessorOutputPort(processor, activityPort
+ .getName(), activityPort.getDepth(), activityPort
+ .getGranularDepth());
+ editList.add(edits.getAddProcessorOutputPortEdit(processor,
+ processorOutputPort));
+ editList.add(edits.getAddActivityOutputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ output = processorOutputPort;
+ }
+ return output;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyDataTypeEdit.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyDataTypeEdit.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyDataTypeEdit.java
new file mode 100644
index 0000000..e13c264
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/edits/AddBiomobyDataTypeEdit.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.edits;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.EventForwardingOutputPort;
+import net.sf.taverna.t2.workflowmodel.EventHandlingInputPort;
+import net.sf.taverna.t2.workflowmodel.InputPort;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorInputPort;
+import net.sf.taverna.t2.workflowmodel.ProcessorOutputPort;
+import net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit;
+import net.sf.taverna.t2.workflowmodel.impl.DataflowImpl;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class AddBiomobyDataTypeEdit extends AbstractDataflowEdit {
+
+ private final BiomobyActivity activity;
+ private Edits edits;
+ private final String objectName;
+
+ private Edit<?> compoundEdit = null;
+ private Edit<?> linkEdit = null;
+ private Edit<?> upstreamObjectEdit = null;
+
+
+ public AddBiomobyDataTypeEdit(Dataflow dataflow,BiomobyActivity activity,String objectName, Edits edits) {
+ super(dataflow);
+ this.activity = activity;
+ this.objectName = objectName;
+ this.edits = edits;
+
+ }
+
+
+
+
+
+ /* (non-Javadoc)
+ * @see net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit#doEditAction(net.sf.taverna.t2.workflowmodel.impl.DataflowImpl)
+ */
+ @Override
+ protected void doEditAction(DataflowImpl dataflow) throws EditException {
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+
+
+ String defaultName = objectName;
+ defaultName = defaultName.split("\\(")[0];
+ String name = Tools.uniqueProcessorName(objectName, dataflow);
+
+ BiomobyObjectActivityConfigurationBean configBean = new BiomobyObjectActivityConfigurationBean();
+ configBean.setMobyEndpoint(activity
+ .getConfiguration()
+ .getMobyEndpoint());
+ configBean.setAuthorityName("");
+ configBean.setServiceName(defaultName);
+
+
+ net.sf.taverna.t2.workflowmodel.Processor sourceProcessor = edits
+ .createProcessor(name);
+ BiomobyObjectActivity boActivity = new BiomobyObjectActivity();
+ Edit<?> configureActivityEdit = edits
+ .getConfigureActivityEdit(
+ boActivity, configBean);
+ editList.add(configureActivityEdit);
+
+ editList
+ .add(edits
+ .getDefaultDispatchStackEdit(sourceProcessor));
+
+ Edit<?> addActivityToProcessorEdit = edits
+ .getAddActivityEdit(
+ sourceProcessor,
+ boActivity);
+ editList
+ .add(addActivityToProcessorEdit);
+
+ String inputPortName = determineInputPortName(defaultName,objectName);
+
+ editList.add(edits.getAddProcessorEdit(
+ dataflow,
+ sourceProcessor));
+
+ compoundEdit = new CompoundEdit(
+ editList);
+ compoundEdit.doEdit();
+
+ net.sf.taverna.t2.workflowmodel.Processor sinkProcessor = Tools
+ .getProcessorsWithActivity(
+ dataflow,
+ activity).iterator()
+ .next();
+
+ List<Edit<?>> linkEditList = new ArrayList<Edit<?>>();
+ EventHandlingInputPort sinkPort = getSinkPort(
+ sinkProcessor, activity,
+ inputPortName, linkEditList);
+ EventForwardingOutputPort sourcePort = getSourcePort(
+ sourceProcessor, boActivity,
+ "mobyData", linkEditList);
+
+ linkEditList.add(Tools
+ .getCreateAndConnectDatalinkEdit(
+ dataflow,
+ sourcePort, sinkPort, edits));
+ linkEdit = new CompoundEdit(linkEditList);
+ linkEdit.doEdit();
+
+ if (!(defaultName.equalsIgnoreCase("Object")
+ || defaultName.equalsIgnoreCase("String")
+ || defaultName.equalsIgnoreCase("Integer")
+ || defaultName.equalsIgnoreCase("Float")
+ || defaultName.equalsIgnoreCase("DateTime"))) {
+ upstreamObjectEdit=new AddUpstreamObjectEdit(dataflow,sourceProcessor,boActivity, edits);
+ upstreamObjectEdit.doEdit();
+
+ }
+ }
+
+ protected String determineInputPortName(String defaultName,String objectName) {
+ String inputPortName = objectName
+ .replaceAll("'", "");
+ if (inputPortName.indexOf("()") > 0)
+ inputPortName = inputPortName
+ .replaceAll("\\(\\)",
+ "\\(_ANON_\\)");
+ return inputPortName;
+ }
+
+ /* (non-Javadoc)
+ * @see net.sf.taverna.t2.workflowmodel.impl.AbstractDataflowEdit#undoEditAction(net.sf.taverna.t2.workflowmodel.impl.DataflowImpl)
+ */
+ @Override
+ protected void undoEditAction(DataflowImpl dataflow) {
+ if (linkEdit!=null && linkEdit.isApplied())
+ linkEdit.undo();
+ if (compoundEdit!=null && compoundEdit.isApplied())
+ compoundEdit.undo();
+ if (upstreamObjectEdit!=null && upstreamObjectEdit.isApplied()) {
+ upstreamObjectEdit.undo();
+ }
+
+ }
+
+ private EventHandlingInputPort getSinkPort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ InputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityInputPort(activity, portName);
+ // check if processor port exists
+ EventHandlingInputPort input = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorInputPort(processor, activity, activityPort);
+ if (input == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorInputPort processorInputPort = edits
+ .createProcessorInputPort(processor,
+ activityPort.getName(), activityPort.getDepth());
+ editList.add(edits.getAddProcessorInputPortEdit(processor,
+ processorInputPort));
+ editList.add(edits.getAddActivityInputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ input = processorInputPort;
+ }
+ return input;
+ }
+
+ private EventForwardingOutputPort getSourcePort(
+ net.sf.taverna.t2.workflowmodel.Processor processor,
+ Activity<?> activity, String portName, List<Edit<?>> editList) {
+ OutputPort activityPort = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getActivityOutputPort(activity, portName);
+ // check if processor port exists
+ EventForwardingOutputPort output = net.sf.taverna.t2.workflowmodel.utils.Tools
+ .getProcessorOutputPort(processor, activity, activityPort);
+ if (output == null) {
+ // port doesn't exist so create a processor port and map it
+ ProcessorOutputPort processorOutputPort = edits
+ .createProcessorOutputPort(processor, activityPort
+ .getName(), activityPort.getDepth(), activityPort
+ .getGranularDepth());
+ editList.add(edits.getAddProcessorOutputPortEdit(processor,
+ processorOutputPort));
+ editList.add(edits.getAddActivityOutputPortMappingEdit(activity,
+ activityPort.getName(), activityPort.getName()));
+ output = processorOutputPort;
+ }
+ return output;
+ }
+
+}
[03/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java
new file mode 100644
index 0000000..a7b873c
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+
+package net.sf.taverna.t2.activities.biomoby;
+
+import org.biomoby.shared.MobyService;
+import org.biomoby.shared.Central;
+
+/**
+ * This class is used to create a threaded call to the Biomoby registry that
+ * retrieves WSDL for services. This is done, because the Biomoby API assumes
+ * that before calling a service the WSDL is retrieved.
+ *
+ * @author Eddie Kawas
+ *
+ */
+public class RetrieveWsdlThread extends Thread {
+ // the service to get wsdl document
+ MobyService service = null;
+
+ // the registry that we will get the document from
+ Central worker = null;
+
+ /**
+ * Constructor
+ *
+ * @param worker
+ * the Central registry that we query for wsdl
+ * @param service
+ * the service that we want wsdl for
+ */
+ RetrieveWsdlThread(Central worker, MobyService service) {
+ super("BioMOBY RetrieveWsdlThread");
+ this.service = service;
+ this.worker = worker;
+ setDaemon(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Thread#run()
+ */
+ public void run() {
+ try {
+ worker.getServiceWSDL(service.getName(), service.getAuthority());
+ } catch (Exception e) {
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/XMLUtilities.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/XMLUtilities.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/XMLUtilities.java
new file mode 100644
index 0000000..d791329
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/XMLUtilities.java
@@ -0,0 +1,1927 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.Utils;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+/**
+ *
+ * @author Eddie Kawas
+ *
+ */
+@SuppressWarnings("unchecked")
+public class XMLUtilities {
+
+ // private variables
+ // machine independent new line character
+ public final static String newline = System.getProperty("line.separator");
+
+ // class variable to keep persistant queryIDs
+ private static int queryCount = 0;
+
+ // the moby namespaces
+ public final static Namespace MOBY_NS = Namespace.getNamespace("moby",
+ "http://www.biomoby.org/moby");
+
+ /**
+ *
+ * @param message
+ * the structurally valid BioMoby message as a String
+ * @return true if the message contains multiple invocations, false
+ * otherwise.
+ * @throws MobyException
+ * if the message is null
+ */
+ public static boolean isMultipleInvocationMessage(String message)
+ throws MobyException {
+ if (message == null)
+ throw new MobyException(
+ newline
+ + "null 'xml' found where it was not expected in isMultipleInvocationMessage(String message).");
+ Element documentElement = getDOMDocument(message).getRootElement();
+ return isMultipleInvocationMessage(documentElement);
+ }
+
+ /**
+ *
+ * @param message
+ * the structurally valid BioMoby message as an Element
+ * @return true if the message contains multiple invocations, false
+ * otherwise.
+ * @throws MobyException
+ * if the message is null
+ */
+ public static boolean isMultipleInvocationMessage(Element message)
+ throws MobyException {
+ if (message == null)
+ throw new MobyException(
+ newline
+ + "null 'xml' found where it was not expected in isMultipleInvocationMessage(Element message).");
+ Element e = (Element) message.clone();
+ List list = new ArrayList();
+ listChildren(e, "mobyData", list);
+ if (list != null)
+ if (list.size() > 1)
+ return true;
+ return false;
+ }
+
+ /**
+ *
+ * @param element
+ * the element to extract the list of simples from. This method
+ * assumes that you are passing in a single invokation and that
+ * you wish to extract the Simples not contained in any
+ * collections. This method also maintains any past queryIDs.
+ * @return an array of elements that are fully 'wrapped' simples.
+ * @throws MobyException
+ * if the Element isnt structurally valid in terms of Moby
+ * message structure
+ */
+ public static Element[] getListOfSimples(Element element)
+ throws MobyException {
+ Element temp = (Element) element.clone();
+ Element e = (Element) element.clone();
+ String queryID = "";
+
+ if (isMultipleInvocationMessage(element))
+ return new Element[] {};
+
+ Element serviceNotes = getServiceNotes(e);
+
+ // if the current elements name isnt MOBY, see if its direct child is
+ if (!e.getName().equals("MOBY")) {
+ if (e.getChild("MOBY") != null)
+ temp = e.getChild("MOBY");
+ else if (e.getChild("MOBY", MOBY_NS) != null)
+ temp = e.getChild("MOBY", MOBY_NS);
+ else
+ throw new MobyException(newline
+ + "Expected 'MOBY' as the local name for the element "
+ + newline + "and instead received '" + e.getName()
+ + "' (getListOfSimples(Element element).");
+ }
+ // parse the mobyContent node
+ if (temp.getChild("mobyContent") != null)
+ temp = temp.getChild("mobyContent");
+ else if (temp.getChild("mobyContent", MOBY_NS) != null)
+ temp = temp.getChild("mobyContent", MOBY_NS);
+ else
+ throw new MobyException(
+ newline
+ + "Expected 'mobyContent' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getListOfSimples(Element element).");
+
+ // parse the mobyData node
+ if (temp.getChild("mobyData") != null) {
+ temp = temp.getChild("mobyData");
+ } else if (temp.getChild("mobyData", MOBY_NS) != null) {
+ temp = temp.getChild("mobyData", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyData' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getListOfSimples(Element element).");
+ }
+
+ // temp == mobyData now we need to get the queryID and save it
+ if (temp.getAttribute("queryID") != null) {
+ queryID = temp.getAttribute("queryID").getValue();
+ } else if (temp.getAttribute("queryID", MOBY_NS) != null) {
+ queryID = temp.getAttribute("queryID", MOBY_NS).getValue();
+ } else {
+ // create a new one -> shouldnt happen very often
+ queryID = "a" + queryCount++;
+ }
+
+ // now we iterate through all of the direct children called Simple, wrap
+ // them individually and set the queryID = queryID
+ List list = temp.getChildren("Simple", MOBY_NS);
+ if (list.isEmpty()) {
+ list = temp.getChildren("Simple");
+ if (list.isEmpty()) {
+ return new Element[] {};
+ }
+ }
+ // non empty list
+ Element[] elements = new Element[list.size()];
+ int index = 0;
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Element next = (Element) it.next();
+ elements[index++] = createMobyDataElementWrapper(next, queryID,
+ serviceNotes);
+ }
+ return elements;
+ }
+
+ /**
+ *
+ * @param message
+ * the String of xml to extract the list of simples from. This
+ * method assumes that you are passing in a single invokation and
+ * that you wish to extract the Simples not contained in any
+ * collections. This method also maintains any past queryIDs.
+ * @return an array of Strings that represent fully 'wrapped' simples.
+ * @throws MobyException
+ * if the String doesnt contain a structurally valid Moby
+ * message structure or if an unexpected error occurs
+ */
+ public static String[] getListOfSimples(String message)
+ throws MobyException {
+ Element element = getDOMDocument(message).getRootElement();
+ Element[] elements = getListOfSimples(element);
+ String[] strings = new String[elements.length];
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int count = 0; count < elements.length; count++) {
+ try {
+ strings[count] = outputter.outputString(elements[count]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unexpected error occured while creating String[]:"
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param message
+ * the String to extract the list of collections from and assumes
+ * that you are passing in a single invocation message.
+ * @return an array of Strings representing all of the fully 'wrapped'
+ * collections in the message.
+ * @throws MobyException
+ * if the the element contains an invalid BioMOBY message
+ */
+ public static String[] getListOfCollections(String message)
+ throws MobyException {
+ Element element = getDOMDocument(message).getRootElement();
+ Element[] elements = getListOfCollections(element);
+ String[] strings = new String[elements.length];
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int count = 0; count < elements.length; count++) {
+ try {
+ strings[count] = outputter.outputString(elements[count]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unexpected error occured while creating String[]:"
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param element
+ * the element to extract the list of collections from and
+ * assumes that you are passing in a single invocation message.
+ * @return an array of Elements representing all of the fully 'wrapped'
+ * collections in the message
+ * @throws MobyException
+ * if the element contains an invalid BioMOBY message
+ */
+ public static Element[] getListOfCollections(Element element)
+ throws MobyException {
+ Element temp = (Element) element.clone();
+ Element e = (Element) element.clone();
+ String queryID = "";
+
+ if (isMultipleInvocationMessage(e))
+ return new Element[] {};
+
+ Element serviceNotes = getServiceNotes(e);
+
+ // if the current elements name isnt MOBY, see if its direct child is
+ if (!e.getName().equals("MOBY")) {
+ if (e.getChild("MOBY") != null)
+ temp = e.getChild("MOBY");
+ else if (e.getChild("MOBY", MOBY_NS) != null)
+ temp = e.getChild("MOBY", MOBY_NS);
+ else
+ throw new MobyException(newline
+ + "Expected 'MOBY' as the local name for the element "
+ + newline + "and instead received '" + e.getName()
+ + "' (getListOfCollections(Element element).");
+ }
+ // parse the mobyContent node
+ if (temp.getChild("mobyContent") != null)
+ temp = temp.getChild("mobyContent");
+ else if (temp.getChild("mobyContent", MOBY_NS) != null)
+ temp = temp.getChild("mobyContent", MOBY_NS);
+ else
+ throw new MobyException(
+ newline
+ + "Expected 'mobyContent' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getListOfCollections(Element element).");
+
+ // parse the mobyData node
+ if (temp.getChild("mobyData") != null) {
+ temp = temp.getChild("mobyData");
+ } else if (temp.getChild("mobyData", MOBY_NS) != null) {
+ temp = temp.getChild("mobyData", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyData' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getListOfCollections(Element element).");
+ }
+
+ // temp == mobyData now we need to get the queryID and save it
+ if (temp.getAttribute("queryID") != null) {
+ queryID = temp.getAttribute("queryID").getValue();
+ } else if (temp.getAttribute("queryID", MOBY_NS) != null) {
+ queryID = temp.getAttribute("queryID", MOBY_NS).getValue();
+ } else {
+ // create a new one -> shouldnt happen very often
+ queryID = "a" + queryCount++;
+ }
+
+ // now we iterate through all of the direct children called Simple, wrap
+ // them individually and set the queryID = queryID
+ List list = temp.getChildren("Collection", MOBY_NS);
+ if (list.isEmpty()) {
+ list = temp.getChildren("Collection");
+ if (list.isEmpty()) {
+ return new Element[] {};
+ }
+ }
+ // non empty list
+ Element[] elements = new Element[list.size()];
+ int index = 0;
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Element next = (Element) it.next();
+ elements[index++] = createMobyDataElementWrapper(next, queryID,
+ serviceNotes);
+ }
+ return elements;
+ }
+
+ /**
+ * This method assumes a single invocation was passed to it
+ * <p>
+ *
+ * @param name
+ * the article name of the simple that you are looking for
+ * @param xml
+ * the xml that you want to query
+ * @return a String object that represent the simple found.
+ * @throws MobyException
+ * if no simple was found given the article name and/or data
+ * type or if the xml was not valid moby xml or if an unexpected
+ * error occurs.
+ */
+ public static String getSimple(String name, String xml)
+ throws MobyException {
+ Element element = getDOMDocument(xml).getRootElement();
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ Element simples = getSimple(name, element);
+ if (simples != null) {
+ try {
+ return outputter.outputString(simples);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unexpected error occured while creating String[]:"
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ throw new MobyException(newline + "The simple named '" + name
+ + "' was not found in the xml:" + newline + xml + newline);
+ }
+
+ /**
+ * This method assumes a single invocation was passed to it
+ * <p>
+ *
+ * @param name
+ * the article name of the simple that you are looking for
+ * @param element
+ * the Element that you want to query
+ * @return an Element that represents the simple found.
+ * @throws MobyException
+ * if no simple was found given the article name and/or data
+ * type or if the xml was not valid moby xml or if an unexpected
+ * error occurs.
+ */
+ public static Element getSimple(String name, Element element)
+ throws MobyException {
+ Element el = (Element) element.clone();
+ Element[] elements = getListOfSimples(el);
+ // try matching based on type(less impt) and/or article name (more impt)
+ for (int i = 0; i < elements.length; i++) {
+ // PRE: elements[i] is a fully wrapped element
+ Element e = elements[i];
+ if (e.getChild("mobyContent") != null) {
+ e = e.getChild("mobyContent");
+ } else if (e.getChild("mobyContent", MOBY_NS) != null) {
+ e = e.getChild("mobyContent", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyContent' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getSimple(String name, "
+ + "Element element).");
+ }
+ if (e.getChild("mobyData") != null) {
+ e = e.getChild("mobyData");
+ } else if (e.getChild("mobyData", MOBY_NS) != null) {
+ e = e.getChild("mobyData", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyData' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getSimple(String name,"
+ + " Element element).");
+ }
+ if (e.getChild("Simple") != null) {
+ e = e.getChild("Simple");
+ } else if (e.getChild("Simple", MOBY_NS) != null) {
+ e = e.getChild("Simple", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'Simple' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getSimple(String name,"
+ + " Element element).");
+ }
+ // e == Simple -> check its name as long as name != ""
+ if (!name.equals(""))
+ if (e.getAttributeValue("articleName") != null) {
+ String value = e.getAttributeValue("articleName");
+ if (value.equals(name)) {
+ return e;
+ }
+ } else if (e.getAttributeValue("articleName", MOBY_NS) != null) {
+ String value = e.getAttributeValue("articleName", MOBY_NS);
+ if (value.equals(name)) {
+ return e;
+ }
+ }
+
+ }
+ throw new MobyException(newline
+ + "The simple named '"
+ + name
+ + "' was not found in the xml:"
+ + newline
+ + (new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false))).outputString(element)
+ + newline);
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml containing a single invocation message to
+ * extract the queryID from
+ * @return the queryID contained in the xml or a generated one if one doesnt
+ * exist
+ * @throws MobyException
+ * if the String of xml is invalid or if the message is a
+ * multiple invocation message
+ */
+ public static String getQueryID(String xml) throws MobyException {
+ return getQueryID(getDOMDocument(xml).getRootElement());
+ }
+
+ /**
+ *
+ * @param xml
+ * a single invocation message to extract the queryID from
+ * @return the queryID contained in the xml or a generated one if one doesnt
+ * exist
+ * @throws if
+ * the message is a multiple invocation message
+ */
+ public static String getQueryID(Element xml) throws MobyException {
+ Element temp = (Element) xml.clone();
+ Element e = (Element) xml.clone();
+
+ if (isMultipleInvocationMessage(e))
+ throw new MobyException(
+ "Unable to retrieve the queryID from the BioMOBY message because a message with greater than one IDs exists.");
+
+ if (!e.getName().equals("MOBY")) {
+ if (e.getChild("MOBY") != null)
+ temp = e.getChild("MOBY");
+ else if (e.getChild("MOBY", MOBY_NS) != null)
+ temp = e.getChild("MOBY", MOBY_NS);
+ }
+ // parse the mobyContent node
+ if (temp.getChild("mobyContent") != null)
+ temp = temp.getChild("mobyContent");
+ else if (temp.getChild("mobyContent", MOBY_NS) != null)
+ temp = temp.getChild("mobyContent", MOBY_NS);
+
+ // parse the mobyData node
+ if (temp.getChild("mobyData") != null) {
+ temp = temp.getChild("mobyData");
+ } else if (temp.getChild("mobyData", MOBY_NS) != null) {
+ temp = temp.getChild("mobyData", MOBY_NS);
+ }
+
+ // temp == mobyData now we need to get the queryID and save it
+ if (temp.getAttribute("queryID") != null) {
+ return temp.getAttribute("queryID").getValue();
+ } else if (temp.getAttribute("queryID", MOBY_NS) != null) {
+ return temp.getAttribute("queryID", MOBY_NS).getValue();
+ } else {
+ // create a new one -> shouldnt happen very often
+ return "a" + queryCount++;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml containing a single invocation message to
+ * extract the queryID from
+ * @return the element passed in to the method with the queryID set if the
+ * message was valid.
+ * @throws MobyException
+ * if the String of xml is syntatically invalid or if the
+ * message is a multiple invocation message
+ */
+ public static String setQueryID(String xml, String id) throws MobyException {
+ return new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(
+ false)).outputString(setQueryID(getDOMDocument(xml)
+ .getRootElement(), id));
+ }
+
+ /**
+ *
+ * @param xml
+ * a single invocation message to extract the queryID from
+ * @return the element passed in to the method with the queryID set if the
+ * message was valid.
+ * @throws MobyException
+ * if the message is a multiple invocation message
+ */
+ public static Element setQueryID(Element xml, String id)
+ throws MobyException {
+ Element e = (Element) xml.clone();
+ Element temp = e;
+ if (isMultipleInvocationMessage(e))
+ throw new MobyException(
+ "Unable to set the queryID, because there are more than one queryID to set!");
+ if (!e.getName().equals("MOBY")) {
+ if (e.getChild("MOBY") != null)
+ temp = e.getChild("MOBY");
+ else if (e.getChild("MOBY", MOBY_NS) != null)
+ temp = e.getChild("MOBY", MOBY_NS);
+ }
+ // parse the mobyContent node
+ if (temp.getChild("mobyContent") != null)
+ temp = temp.getChild("mobyContent");
+ else if (temp.getChild("mobyContent", MOBY_NS) != null)
+ temp = temp.getChild("mobyContent", MOBY_NS);
+
+ // parse the mobyData node
+ if (temp.getChild("mobyData") != null) {
+ temp = temp.getChild("mobyData");
+ } else if (temp.getChild("mobyData", MOBY_NS) != null) {
+ temp = temp.getChild("mobyData", MOBY_NS);
+ }
+
+ temp.removeAttribute("queryID");
+ temp.removeAttribute("queryID", MOBY_NS);
+ temp.setAttribute("queryID", (id == null || id == "" ? "a"
+ + queryCount++ : id), MOBY_NS);
+ return e;
+ }
+
+ /**
+ *
+ * @param name
+ * the articlename of the simple that you wish to extract
+ * @param xml
+ * the xml message
+ * @return the wrapped simple if it exists
+ * @throws MobyException
+ * if the message is a multiple invocation message or if the xml
+ * is syntatically invalid.
+ */
+ public static String getWrappedSimple(String name, String xml)
+ throws MobyException {
+ Element element = getWrappedSimple(name, getDOMDocument(xml)
+ .getRootElement());
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return outputter.outputString(element);
+ }
+
+ /**
+ *
+ * @param name
+ * the articlename of the simple that you wish to extract
+ * @param xml
+ * the xml message
+ * @return the wrapped simple if it exists
+ * @throws MobyException
+ * if the message is a multiple invocation message.
+ */
+ public static Element getWrappedSimple(String name, Element element)
+ throws MobyException {
+ Element e = (Element) element.clone();
+ String queryID = getQueryID(e);
+ Element serviceNotes = getServiceNotes(e);
+ Element simple = getSimple(name, e);
+ return createMobyDataElementWrapper(simple, queryID, serviceNotes);
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract
+ * @param element
+ * the element to extract the collection from
+ * @return the collection if found
+ * @throws MobyException
+ * if the message is invalid
+ */
+ public static Element getCollection(String name, Element element)
+ throws MobyException {
+ Element el = (Element) element.clone();
+ Element[] elements = getListOfCollections(el);
+ for (int i = 0; i < elements.length; i++) {
+ // PRE: elements[i] is a fully wrapped element
+ Element e = elements[i];
+ if (e.getChild("mobyContent") != null) {
+ e = e.getChild("mobyContent");
+ } else if (e.getChild("mobyContent", MOBY_NS) != null) {
+ e = e.getChild("mobyContent", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyContent' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getCollection(String name, "
+ + "Element element).");
+ }
+ if (e.getChild("mobyData") != null) {
+ e = e.getChild("mobyData");
+ } else if (e.getChild("mobyData", MOBY_NS) != null) {
+ e = e.getChild("mobyData", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected 'mobyData' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getCollection(String name,"
+ + " Element element).");
+ }
+ if (e.getChild("Collection") != null) {
+ e = e.getChild("Collection");
+ } else if (e.getChild("Collection", MOBY_NS) != null) {
+ e = e.getChild("Collection", MOBY_NS);
+ } else {
+ // TODO should i throw exception or continue?
+ throw new MobyException(
+ newline
+ + "Expected 'Collection' as the local name for the next child element but it "
+ + newline
+ + "wasn't there. I even tried a qualified name (getCollection(String name,"
+ + " Element element).");
+ }
+ // e == collection -> check its name
+ if (e.getAttributeValue("articleName") != null) {
+ String value = e.getAttributeValue("articleName");
+ if (value.equals(name)) {
+ return e;
+ }
+ } else if (e.getAttributeValue("articleName", MOBY_NS) != null) {
+ String value = e.getAttributeValue("articleName", MOBY_NS);
+ if (value.equals(name)) {
+ return e;
+ }
+ }
+ if (elements.length == 1) {
+ if (e.getAttributeValue("articleName") != null) {
+ String value = e.getAttributeValue("articleName");
+ if (value.equals("")) {
+ // rename it to make it compatible with moby
+ e.setAttribute("articleName", name, MOBY_NS);
+ return e;
+ }
+ } else if (e.getAttributeValue("articleName", MOBY_NS) != null) {
+ String value = e.getAttributeValue("articleName", MOBY_NS);
+ if (value.equals("")) {
+ // rename it to make it compatible with moby
+ e.setAttribute("articleName", name, MOBY_NS);
+ return e;
+ }
+ }
+ }
+ // name didnt match, so too bad ;-)
+ }
+ throw new MobyException(
+ newline
+ + "The Collection named '"
+ + name
+ + "' was not found in the xml:"
+ + newline
+ + (new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false)))
+ .outputString(element)
+ + newline
+ + "Note: A collection of that may exist, but may be contained in a multiple invocation message.");
+ }
+
+ /**
+ *
+ * @param name
+ * @param xml
+ * @return
+ * @throws MobyException
+ */
+ public static String getCollection(String name, String xml)
+ throws MobyException {
+ Element element = getDOMDocument(xml).getRootElement();
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ Element collection = getCollection(name, element);
+ if (collection != null)
+ return outputter.outputString(collection);
+ return null;
+ }
+
+ /**
+ *
+ * @param name
+ * @param element
+ * @return
+ * @throws MobyException
+ */
+ public static Element getWrappedCollection(String name, Element element)
+ throws MobyException {
+ Element e = (Element) element.clone();
+ String queryID = getQueryID(e);
+ Element collection = getCollection(name, e);
+ Element serviceNotes = getServiceNotes(e);
+ return createMobyDataElementWrapper(collection, queryID, serviceNotes);
+ }
+
+ /**
+ *
+ * @param name
+ * @param xml
+ * @return
+ * @throws MobyException
+ */
+ public static String getWrappedCollection(String name, String xml)
+ throws MobyException {
+ Element element = getWrappedCollection(name, getDOMDocument(xml)
+ .getRootElement());
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return outputter.outputString(element);
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract the simples from.
+ * @param xml
+ * the XML to extract from
+ * @return an array of String objects that represent the simples
+ * @throws MobyException
+ */
+ public static String[] getSimplesFromCollection(String name, String xml)
+ throws MobyException {
+ Element[] elements = getSimplesFromCollection(name, getDOMDocument(xml)
+ .getRootElement());
+ String[] strings = new String[elements.length];
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int i = 0; i < elements.length; i++) {
+ try {
+ strings[i] = output.outputString(elements[i]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unknown error occured while creating String[]."
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract the simples from.
+ * @param element
+ * the Element to extract from
+ * @return an array of Elements objects that represent the simples
+ * @throws MobyException
+ */
+ public static Element[] getSimplesFromCollection(String name,
+ Element element) throws MobyException {
+ Element e = (Element) element.clone();
+ // exception thrown if not found
+ Element collection = getCollection(name, e);
+
+ List list = collection.getChildren("Simple");
+ if (list.isEmpty())
+ list = collection.getChildren("Simple", MOBY_NS);
+ if (list.isEmpty())
+ return new Element[] {};
+ Vector vector = new Vector();
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Object o = it.next();
+ if (o instanceof Element) {
+ ((Element) o).setAttribute("articleName", name, MOBY_NS);
+ if (((Element) o).getChildren().size() > 0)
+ vector.add(o);
+ }
+
+ }
+ Element[] elements = new Element[vector.size()];
+ vector.copyInto(elements);
+ return elements;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the simples that you would like to extract. The
+ * name can be collection name as well. This method extracts
+ * simples from all invocation messages.
+ * @param xml
+ * the xml to extract the simples from
+ * @return a String[] of Simples that you are looking for, taken from
+ * collections with your search name as well as simple elements with
+ * the search name
+ * @throws MobyException
+ * if there is a problem with the BioMOBY message
+ */
+ public static String[] getAllSimplesByArticleName(String name, String xml)
+ throws MobyException {
+ Element[] elements = getAllSimplesByArticleName(name, getDOMDocument(
+ xml).getRootElement());
+ String[] strings = new String[elements.length];
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int i = 0; i < elements.length; i++) {
+ try {
+ strings[i] = output.outputString(elements[i]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unknown error occured while creating String[]."
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the simples that you would like to extract. The
+ * name can be collection name as well. This method extracts
+ * simples from all invocation messages.
+ * @param element
+ * the xml to extract the simples from
+ * @return a String[] of Simples that you are looking for, taken from
+ * collections with your search name as well as simple elements with
+ * the search name
+ * @throws MobyException
+ * if there is a problem with the BioMOBY message
+ */
+ public static Element[] getAllSimplesByArticleName(String name,
+ Element element) throws MobyException {
+ Element e = (Element) element.clone();
+ Element[] invocations = getSingleInvokationsFromMultipleInvokations(e);
+ Vector vector = new Vector();
+ for (int i = 0; i < invocations.length; i++) {
+ Element collection = null;
+ try {
+ collection = getCollection(name, invocations[i]);
+ } catch (MobyException me) {
+
+ }
+ if (collection != null) {
+ List list = collection.getChildren("Simple");
+ if (list.isEmpty())
+ list = collection.getChildren("Simple", MOBY_NS);
+ if (list.isEmpty())
+ return new Element[] {};
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Object o = it.next();
+ if (o instanceof Element) {
+ ((Element) o)
+ .setAttribute("articleName", name, MOBY_NS);
+ }
+ vector.add(o);
+ }
+ }
+ collection = null;
+
+ Element[] potentialSimples = getListOfSimples(invocations[i]);
+ for (int j = 0; j < potentialSimples.length; j++) {
+ Element mobyData = extractMobyData(potentialSimples[j]);
+ Element simple = mobyData.getChild("Simple");
+ if (simple == null)
+ simple = mobyData.getChild("Simple", MOBY_NS);
+ if (simple != null) {
+ if (simple.getAttribute("articleName") != null) {
+ if (simple.getAttribute("articleName").getValue()
+ .equals(name))
+ vector.add(simple);
+ } else if (simple.getAttribute("articleName", MOBY_NS) != null) {
+ if (simple.getAttribute("articleName", MOBY_NS)
+ .getValue().equals(name))
+ vector.add(simple);
+ }
+ }
+
+ }
+ }
+
+ Element[] elements = new Element[vector.size()];
+ vector.copyInto(elements);
+ return elements;
+ }
+
+ /**
+ *
+ * @param xml
+ * the XML to extract from
+ * @return an array of String objects that represent the simples
+ * @throws MobyException
+ */
+ public static String[] getSimplesFromCollection(String xml)
+ throws MobyException {
+ Element[] elements = getSimplesFromCollection(getDOMDocument(xml)
+ .getRootElement());
+ String[] strings = new String[elements.length];
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int i = 0; i < elements.length; i++) {
+ try {
+ strings[i] = output.outputString(elements[i]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unknown error occured while creating String[]."
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract the simples from.
+ * @param element
+ * the Element to extract from
+ * @return an array of Elements objects that represent the 'unwrapped'
+ * simples
+ * @throws MobyException
+ */
+ public static Element[] getSimplesFromCollection(Element element)
+ throws MobyException {
+ Element e = (Element) element.clone();
+ Element mobyData = extractMobyData(e);
+
+ Element collection = mobyData.getChild("Collection");
+ if (collection == null)
+ collection = mobyData.getChild("Collection", MOBY_NS);
+
+ List list = collection.getChildren("Simple");
+ if (list.isEmpty())
+ list = collection.getChildren("Simple", MOBY_NS);
+ if (list.isEmpty())
+ return new Element[] {};
+ Vector vector = new Vector();
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ vector.add(it.next());
+ }
+ Element[] elements = new Element[vector.size()];
+ vector.copyInto(elements);
+ return elements;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract the simples from.
+ * @param xml
+ * the XML to extract from
+ * @return an array of String objects that represent the simples, with the
+ * name of the collection
+ * @throws MobyException
+ * if the collection doesnt exist or the xml is invalid
+ */
+ public static String[] getWrappedSimplesFromCollection(String name,
+ String xml) throws MobyException {
+ Element[] elements = getWrappedSimplesFromCollection(name,
+ getDOMDocument(xml).getRootElement());
+ String[] strings = new String[elements.length];
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ for (int i = 0; i < elements.length; i++) {
+ try {
+ strings[i] = output.outputString(elements[i]);
+ } catch (Exception e) {
+ throw new MobyException(newline
+ + "Unknown error occured while creating String[]."
+ + newline + Utils.format(e.getLocalizedMessage(), 3));
+ }
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param name
+ * the name of the collection to extract the simples from.
+ * @param element
+ * the Element to extract from
+ * @return an array of Elements objects that represent the simples, with the
+ * name of the collection
+ * @throws MobyException
+ * MobyException if the collection doesnt exist or the xml is
+ * invalid
+ */
+ public static Element[] getWrappedSimplesFromCollection(String name,
+ Element element) throws MobyException {
+ Element el = (Element) element.clone();
+ String queryID = getQueryID(el);
+ Element collection = getCollection(name, el);
+ Element serviceNotes = getServiceNotes(el);
+ List list = collection.getChildren("Simple");
+ if (list.isEmpty())
+ list = collection.getChildren("Simple", MOBY_NS);
+ if (list.isEmpty())
+ return new Element[] {};
+ Vector vector = new Vector();
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ Element e = (Element) it.next();
+ e.setAttribute("articleName", name, MOBY_NS);
+ e = createMobyDataElementWrapper(e, queryID + "_split"
+ + queryCount++, serviceNotes);
+ vector.add(e);
+ }
+ Element[] elements = new Element[vector.size()];
+ vector.copyInto(elements);
+ return elements;
+ }
+
+ /**
+ *
+ * @param xml
+ * the message to extract the invocation messages from
+ * @return an array of String objects each representing a distinct BioMOBY
+ * invocation message.
+ * @throws MobyException
+ * if the moby message is invalid or if the xml is syntatically
+ * invalid.
+ */
+ public static String[] getSingleInvokationsFromMultipleInvokations(
+ String xml) throws MobyException {
+ Element[] elements = getSingleInvokationsFromMultipleInvokations(getDOMDocument(
+ xml).getRootElement());
+ String[] strings = new String[elements.length];
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+
+ for (int i = 0; i < elements.length; i++) {
+ strings[i] = output.outputString(new Document(elements[i]));
+ }
+ return strings;
+ }
+
+ /**
+ *
+ * @param element
+ * the message to extract the invocation messages from
+ * @return an array of Element objects each representing a distinct
+ * invocation message.
+ * @throws MobyException
+ * if the moby message is invalid.
+ */
+ public static Element[] getSingleInvokationsFromMultipleInvokations(
+ Element element) throws MobyException {
+ Element e = (Element) element.clone();
+ Element serviceNotes = getServiceNotes(e);
+ if (e.getChild("MOBY") != null) {
+ e = e.getChild("MOBY");
+ } else if (e.getChild("MOBY", MOBY_NS) != null) {
+ e = e.getChild("MOBY", MOBY_NS);
+ }
+
+ if (e.getChild("mobyContent") != null) {
+ e = e.getChild("mobyContent");
+ } else if (e.getChild("mobyContent", MOBY_NS) != null) {
+ e = e.getChild("mobyContent", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected a child element called 'mobyContent' and did not receive it in:"
+ + newline
+ + new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false)).outputString(e));
+ }
+ List invocations = e.getChildren("mobyData");
+ if (invocations.isEmpty())
+ invocations = e.getChildren("mobyData", MOBY_NS);
+ Element[] elements = new Element[] {};
+ ArrayList theData = new ArrayList();
+ for (Iterator it = invocations.iterator(); it.hasNext();) {
+ Element MOBY = new Element("MOBY", MOBY_NS);
+ Element mobyContent = new Element("mobyContent", MOBY_NS);
+ if (serviceNotes != null)
+ mobyContent.addContent(serviceNotes.detach());
+ Element mobyData = new Element("mobyData", MOBY_NS);
+ Element next = (Element) it.next();
+ String queryID = next.getAttributeValue("queryID", MOBY_NS);
+ if (queryID == null)
+ queryID = next.getAttributeValue("queryID");
+
+ mobyData.setAttribute("queryID", (queryID == null ? "a"+queryCount++ : queryID), MOBY_NS);
+ mobyData.addContent(next.cloneContent());
+ MOBY.addContent(mobyContent);
+ mobyContent.addContent(mobyData);
+ if (next.getChildren().size() > 0)
+ theData.add(MOBY);
+ }
+ elements = new Element[theData.size()];
+ elements = (Element[]) theData.toArray(elements);
+ return elements;
+ }
+
+ /**
+ *
+ * @param document
+ * the string to create a DOM document from
+ * @return a Document object that represents the string of XML.
+ * @throws MobyException
+ * if the xml is invalid syntatically.
+ */
+ public static Document getDOMDocument(String document) throws MobyException {
+ if (document == null)
+ throw new MobyException(newline
+ + "null found where an XML document was expected.");
+ SAXBuilder builder = new SAXBuilder();
+ // Create the document
+ Document doc = null;
+ try {
+ doc = builder.build(new StringReader(document));
+ } catch (JDOMException e) {
+ throw new MobyException(newline + "Error parsing XML:->" + newline
+ + document + newline
+ + Utils.format(e.getLocalizedMessage(), 3) + ".");
+ } catch (IOException e) {
+ throw new MobyException(newline + "Error parsing XML:->" + newline
+ + Utils.format(e.getLocalizedMessage(), 3) + ".");
+ } catch (Exception e) {
+ throw new MobyException(newline + "Error parsing XML:->" + newline
+ + Utils.format(e.getLocalizedMessage(), 3) + ".");
+ }
+ return doc;
+ }
+
+ /**
+ *
+ * @param elements
+ * the fully wrapped moby simples and/or collections to wrap an
+ * input message around
+ * @param queryID
+ * the queryID for this input
+ * @return a fully wrapped message with an appropriate queryID and elements
+ * added to it
+ * @throws MobyException
+ * if an element is invalid or if the XML is syntatically
+ * invalid.
+ */
+ public static String createServiceInput(String[] elements, String queryID)
+ throws MobyException {
+ Element[] element = new Element[elements.length];
+ for (int i = 0; i < elements.length; i++) {
+ element[i] = getDOMDocument(elements[i]).getRootElement();
+ }
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return output.outputString(createServiceInput(element, queryID));
+ }
+
+ /**
+ *
+ * @param elements
+ * the fully wrapped moby simples and/or collections to wrap an
+ * input message around
+ * @param queryID
+ * the queryID for this input
+ * @return a fully wrapped message with an appropriate queryID and elements
+ * added to it
+ * @throws MobyException
+ * if an element is invalid.
+ */
+ public static Element createServiceInput(Element[] elements, String queryID)
+ throws MobyException {
+ // create the main elements
+ Element MOBY = new Element("MOBY", MOBY_NS);
+ Element mobyContent = new Element("mobyContent", MOBY_NS);
+ Element mobyData = new Element("mobyData", MOBY_NS);
+ mobyData.setAttribute("queryID", (queryID == null ? "" : queryID),
+ MOBY_NS);
+
+ // add the content
+ MOBY.addContent(mobyContent);
+ mobyContent.addContent(mobyData);
+
+ // iterate through elements adding the content of mobyData
+ for (int i = 0; i < elements.length; i++) {
+ Element e = (Element) elements[i].clone();
+ e = extractMobyData(e);
+ mobyData.addContent(e.cloneContent());
+ }
+
+ return MOBY;
+ }
+
+ /**
+ * @param element
+ * the element that contains the moby message that you would like
+ * to extract the mobyData block from (assumes single invocation,
+ * but returns the first mobyData block in a multiple invocation
+ * message).
+ * @return the mobyData element block.
+ * @throws MobyException
+ * if the moby message is invalid
+ */
+ public static Element extractMobyData(Element element) throws MobyException {
+ Element e = (Element) element.clone();
+ if (e.getChild("MOBY") != null) {
+ e = e.getChild("MOBY");
+ } else if (e.getChild("MOBY", MOBY_NS) != null) {
+ e = e.getChild("MOBY", MOBY_NS);
+ }
+
+ if (e.getChild("mobyContent") != null) {
+ e = e.getChild("mobyContent");
+ } else if (e.getChild("mobyContent", MOBY_NS) != null) {
+ e = e.getChild("mobyContent", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected the child element 'mobyContent' and did not receive it in:"
+ + newline
+ + new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false)).outputString(e));
+ }
+
+ if (e.getChild("mobyData") != null) {
+ e = e.getChild("mobyData");
+ } else if (e.getChild("mobyData", MOBY_NS) != null) {
+ e = e.getChild("mobyData", MOBY_NS);
+ } else {
+ throw new MobyException(
+ newline
+ + "Expected the child element 'mobyData' and did not receive it in:"
+ + newline
+ + new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false)).outputString(e));
+ }
+ return e;
+ }
+
+ /**
+ *
+ * @param newName
+ * the new name for this fully wrapped BioMOBY collection
+ * @param element
+ * the fully wrapped BioMOBY collection
+ * @return @return an element 'Collection' representing the renamed collection
+ * @throws MobyException
+ * if the message is invalid
+ */
+ public static Element renameCollection(String newName, Element element)
+ throws MobyException {
+ Element e = (Element) element.clone();
+ Element mobyData = extractMobyData(e);
+ Element coll = mobyData.getChild("Collection");
+ if (coll == null)
+ coll = mobyData.getChild("Collection", MOBY_NS);
+ if (coll == null)
+ return e;
+ coll.removeAttribute("articleName");
+ coll.removeAttribute("articleName", MOBY_NS);
+ coll.setAttribute("articleName", newName, MOBY_NS);
+ return coll;
+ }
+
+ /**
+ *
+ * @param newName
+ * the new name for this fully wrapped BioMOBY collection
+ * @param xml
+ * the fully wrapped BioMOBY collection
+ * @return an element 'Collection' representing the renamed collection
+ * @throws MobyException
+ * if the BioMOBY message is invalid or the xml is syntatically
+ * invalid.
+ */
+ public static String renameCollection(String newName, String xml)
+ throws MobyException {
+ return new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(
+ false)).outputString(renameCollection(newName, getDOMDocument(
+ xml).getRootElement()));
+ }
+
+ /**
+ *
+ * @param oldName
+ * @param newName
+ * @param type
+ * @param xml
+ * @return
+ * @throws MobyException
+ */
+ public static String renameSimple(String newName, String type, String xml)
+ throws MobyException {
+ return new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(
+ false)).outputString(renameSimple(newName, type,
+ getDOMDocument(xml).getRootElement()));
+ }
+
+ /**
+ *
+ * @param oldName
+ * @param newName
+ * @param type
+ * @param element
+ * @return
+ * @throws MobyException
+ */
+ public static Element renameSimple(String newName, String type,
+ Element element) throws MobyException {
+ Element e = (Element) element.clone();
+ Element mobyData = extractMobyData(e);
+ String queryID = getQueryID(e);
+ Element serviceNotes = getServiceNotes(e);
+ Element simple = mobyData.getChild("Simple");
+ if (simple == null)
+ simple = mobyData.getChild("Simple", MOBY_NS);
+ if (simple == null) {
+ return e;
+ }
+ simple.removeAttribute("articleName");
+ simple.removeAttribute("articleName", MOBY_NS);
+ simple.setAttribute("articleName", newName, MOBY_NS);
+ return createMobyDataElementWrapper(simple, queryID, serviceNotes);
+ }
+
+ /**
+ *
+ * @return
+ * @throws MobyException
+ */
+ public static Document createDomDocument() throws MobyException {
+ Document d = new Document();
+ d.setBaseURI(MOBY_NS.getURI());
+ return d;
+ }
+
+ /**
+ *
+ * @param element
+ * @param queryID
+ * @param serviceNotes
+ * @return
+ * @throws MobyException
+ */
+ public static Element createMobyDataElementWrapper(Element element,
+ String queryID, Element serviceNotes) throws MobyException {
+ Element e = (Element) element.clone();
+ Element MOBY = new Element("MOBY", MOBY_NS);
+ Element mobyContent = new Element("mobyContent", MOBY_NS);
+ Element mobyData = new Element("mobyData", MOBY_NS);
+ mobyData.setAttribute("queryID", queryID, MOBY_NS);
+ MOBY.addContent(mobyContent);
+ mobyContent.addContent(mobyData);
+ // add the serviceNotes if they exist
+ if (serviceNotes != null)
+ mobyContent.addContent(serviceNotes.detach());
+
+ if (e != null) {
+ if (e.getName().equals("Simple")) {
+ Element simple = new Element("Simple", MOBY_NS);
+ simple.setAttribute("articleName", (e
+ .getAttributeValue("articleName") == null ? e
+ .getAttributeValue("articleName", MOBY_NS, "") : e
+ .getAttributeValue("articleName", "")), MOBY_NS);
+ simple.addContent(e.cloneContent());
+ if (simple.getChildren().size() > 0)
+ mobyData.addContent(simple.detach());
+ } else if (e.getName().equals("Collection")) {
+ Element collection = new Element("Collection", MOBY_NS);
+ collection.setAttribute("articleName", (e
+ .getAttributeValue("articleName") == null ? e
+ .getAttributeValue("articleName", MOBY_NS, "") : e
+ .getAttributeValue("articleName", "")), MOBY_NS);
+ collection.addContent(e.cloneContent());
+ if (collection.getChildren().size() > 0)
+ mobyData.addContent(collection.detach());
+ }
+ }
+
+ return MOBY;
+ }
+
+ public static Element createMobyDataWrapper(String queryID,
+ Element serviceNotes) throws MobyException {
+
+ Element e = null;
+
+ if (serviceNotes != null)
+ e = (Element) serviceNotes.clone();
+
+ Element MOBY = new Element("MOBY", MOBY_NS);
+ Element mobyContent = new Element("mobyContent", MOBY_NS);
+ if (e != null)
+ mobyContent.addContent(e.detach());
+ Element mobyData = new Element("mobyData", MOBY_NS);
+ mobyData.setAttribute("queryID", queryID, MOBY_NS);
+ MOBY.addContent(mobyContent);
+ mobyContent.addContent(mobyData);
+ return MOBY;
+ }
+
+ /**
+ *
+ * @param xml
+ * @return
+ * @throws MobyException
+ */
+ public static String createMobyDataElementWrapper(String xml)
+ throws MobyException {
+ return createMobyDataElementWrapper(xml, "a" + queryCount++);
+ }
+
+ /**
+ *
+ * @param element
+ * @return
+ * @throws MobyException
+ */
+ public static Element createMobyDataElementWrapper(Element element)
+ throws MobyException {
+ Element serviceNotes = getServiceNotes((Element) element.clone());
+ return createMobyDataElementWrapper(element, "a" + queryCount++,
+ serviceNotes);
+ }
+
+ /**
+ *
+ * @param xml
+ * @param queryID
+ * @return
+ * @throws MobyException
+ */
+ public static String createMobyDataElementWrapper(String xml, String queryID)
+ throws MobyException {
+ if (xml == null)
+ return null;
+ Element serviceNotes = getServiceNotes(getDOMDocument(xml)
+ .getRootElement());
+ Element element = createMobyDataElementWrapper(getDOMDocument(xml)
+ .getRootElement(), queryID, serviceNotes);
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return (element == null ? null : outputter.outputString(element));
+ }
+
+ public static String createMobyDataElementWrapper(String xml,
+ String queryID, Element serviceNotes) throws MobyException {
+ if (xml == null)
+ return null;
+ Element element = createMobyDataElementWrapper(getDOMDocument(xml)
+ .getRootElement(), queryID, serviceNotes);
+ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return (element == null ? null : outputter.outputString(element));
+ }
+
+ /**
+ *
+ * @param elements
+ * @return
+ * @throws MobyException
+ */
+ public static Element createMultipleInvokations(Element[] elements)
+ throws MobyException {
+ Element MOBY = new Element("MOBY", MOBY_NS);
+ Element mobyContent = new Element("mobyContent", MOBY_NS);
+ Element serviceNotes = null;
+ for (int i = 0; i < elements.length; i++) {
+ if (serviceNotes == null) {
+ serviceNotes = getServiceNotes((Element) elements[i].clone());
+ if (serviceNotes != null)
+ mobyContent.addContent(serviceNotes.detach());
+ }
+ Element mobyData = new Element("mobyData", MOBY_NS);
+ Element md = extractMobyData((Element) elements[i].clone());
+ String queryID = getQueryID((Element) elements[i].clone());
+ mobyData.setAttribute("queryID", queryID, MOBY_NS);
+ mobyData.addContent(md.cloneContent());
+ mobyContent.addContent(mobyData);
+ }
+ MOBY.addContent(mobyContent);
+
+ return MOBY;
+ }
+
+ /**
+ *
+ * @param xmls
+ * @return
+ * @throws MobyException
+ */
+ public static String createMultipleInvokations(String[] xmls)
+ throws MobyException {
+ Element[] elements = new Element[xmls.length];
+ for (int i = 0; i < elements.length; i++) {
+ elements[i] = getDOMDocument(xmls[i]).getRootElement();
+ }
+ XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return output.outputString(createMultipleInvokations(elements));
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml
+ * @return true if the xml contains a full moby message (assumes single
+ * invocation, but will return the first mobyData block from a
+ * multiple invocation message).
+ */
+ public static boolean isWrapped(Element element) {
+ try {
+ extractMobyData((Element) element.clone());
+ return true;
+ } catch (MobyException e) {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml
+ * @return true if the xml contains a full moby message (assumes single
+ * invocation, but will return the first mobyData block from a
+ * multiple invocation message).
+ * @throws MobyException
+ * if the xml is syntatically invalid
+ */
+ public static boolean isWrapped(String xml) throws MobyException {
+ Element element = getDOMDocument(xml).getRootElement();
+ return isWrapped(element);
+ }
+
+ /**
+ *
+ * @param element
+ * an Element containing a single invocation
+ * @return true if the element contains a moby collection, false otherwise.
+ * @throws MobyException
+ * if xml is invalid
+ */
+ public static boolean isCollection(Element element) throws MobyException {
+ try {
+ return getListOfCollections((Element) element.clone()).length > 0;
+
+ } catch (MobyException e) {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml containing a single invocation
+ * @return true if the xml contains a moby collection, false otherwise.
+ * @throws MobyException
+ * if xml is invalid
+ */
+ public static boolean isCollection(String xml) throws MobyException {
+ Element element = getDOMDocument(xml).getRootElement();
+ return isCollection(element);
+ }
+
+ /**
+ *
+ * @param xml
+ * a string of xml to check for emptiness
+ * @return true if the element is empty, false otherwise.
+ */
+ public static boolean isEmpty(String xml) {
+ try {
+ return isEmpty(getDOMDocument(xml).getRootElement());
+ } catch (MobyException e) {
+ return true;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * an element to check for emptiness
+ * @return true if the element is empty, false otherwise.
+ */
+ public static boolean isEmpty(Element xml) {
+ try {
+ Element e = extractMobyData((Element) xml.clone());
+ if (e.getChild("Collection") != null)
+ return false;
+ if (e.getChild("Collection", MOBY_NS) != null)
+ return false;
+ if (e.getChild("Simple") != null)
+ return false;
+ if (e.getChild("Simple", MOBY_NS) != null)
+ return false;
+ } catch (MobyException e) {
+ }
+ return true;
+
+ }
+
+ /**
+ *
+ * @param theList
+ * a list of Elements that represent collections (wrapped in a
+ * MobyData tag
+ * @param name
+ * the name to set for the collection
+ * @return a list containing a single wrapped collection Element that contains all
+ * of the simples in the collections in theList
+ * @throws MobyException
+ *
+ */
+ public static List mergeCollections(List theList, String name)
+ throws MobyException {
+ if (theList == null)
+ return new ArrayList();
+ Element mainCollection = new Element("Collection", MOBY_NS);
+ mainCollection.setAttribute("articleName", name, MOBY_NS);
+ String queryID = "";
+ for (Iterator iter = theList.iterator(); iter.hasNext();) {
+ Element mobyData = (Element) iter.next();
+ queryID = getQueryID(mobyData);
+ Element collection = mobyData.getChild("Collection");
+ if (collection == null)
+ collection = mobyData.getChild("Collection", MOBY_NS);
+ if (collection == null)
+ continue;
+ mainCollection.addContent(collection.cloneContent());
+ }
+ theList = new ArrayList();
+ theList
+ .add((createMobyDataElementWrapper(mainCollection, queryID,
+ null)));
+ return theList;
+ }
+
+ /**
+ *
+ * @param element
+ * a full moby message (root element called MOBY) and may be
+ * prefixed
+ * @return the serviceNotes element if it exists, null otherwise.
+ */
+ public static Element getServiceNotes(Element element) {
+ Element serviceNotes = null;
+ Element e = (Element) element.clone();
+ Element mobyContent = e.getChild("mobyContent");
+ if (mobyContent == null)
+ mobyContent = e.getChild("mobyContent", MOBY_NS);
+
+ // should throw exception?
+ if (mobyContent == null)
+ return serviceNotes;
+
+ serviceNotes = mobyContent.getChild("serviceNotes");
+ if (serviceNotes == null)
+ serviceNotes = mobyContent.getChild("serviceNotes", MOBY_NS);
+ // note: servicenotes may be null
+ return serviceNotes;
+ }
+
+ /**
+ *
+ * @param xml
+ * a full moby message (root element called MOBY) and may be
+ * prefixed
+ * @return the serviceNotes element as a string if it exists, null
+ * otherwise.
+ */
+ public static String getServiceNotes(String xml) {
+ try {
+ Element e = getServiceNotes(getDOMDocument(xml).getRootElement());
+ if (e == null)
+ return null;
+ XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return out.outputString(e);
+ } catch (MobyException ex) {
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * a full moby message (root element called MOBY) and may be
+ * prefixed
+ * @return the serviceNotes element if it exists, null otherwise.
+ */
+ public static Element getServiceNotesAsElement(String xml) {
+ try {
+ Element e = getServiceNotes(getDOMDocument(xml).getRootElement());
+ return e;
+ } catch (MobyException ex) {
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @param element
+ * the xml element
+ * @param articleName
+ * the name of the child to extract
+ * @return an element that represents the direct child or null if it wasnt
+ * found.
+ */
+ public static Element getDirectChildByArticleName(Element element,
+ String articleName) {
+ Element e = (Element) element.clone();
+ List list = e.getChildren();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ Object object = iter.next();
+ if (object instanceof Element) {
+ Element child = (Element) object;
+ if (child.getAttributeValue("articleName") != null) {
+ if (child.getAttributeValue("articleName").equals(
+ articleName))
+ return child;
+ } else if (child.getAttributeValue("articleName", MOBY_NS) != null) {
+ if (child.getAttributeValue("articleName", MOBY_NS).equals(
+ articleName)) {
+ return child;
+ }
+ }
+ }
+
+ }
+ return null;
+
+ }
+
+ /**
+ *
+ * @param xml
+ * the string of xml
+ * @param articleName
+ * the name of the child to extract
+ * @return an xml string that represents the direct child or null if it
+ * wasnt found.
+ */
+ public static String getDirectChildByArticleName(String xml,
+ String articleName) {
+ try {
+ Element e = getDirectChildByArticleName(getDOMDocument(xml)
+ .getRootElement(), articleName);
+ if (e == null)
+ return null;
+ XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()
+ .setOmitDeclaration(false));
+ return out.outputString(e);
+ } catch (MobyException me) {
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @param xml
+ * the xml message to test whether or not there is stuff in the
+ * mobyData portion of a message.
+ * @return true if there is data, false otherwise.
+ */
+ public static boolean isThereData(Element xml) {
+ Element e = null;
+ e = (Element) xml.clone();
+ try {
+ e = extractMobyData(e);
+ if (e.getChildren().size() > 0) {
+ // make sure we dont have empty collections or simples
+ if (e.getChild("Collection") != null) {
+ return e.getChild("Collection").getChildren().size() > 0;
+ }
+ if (e.getChild("Collection", MOBY_NS) != null) {
+ return e.getChild("Collection", MOBY_NS).getChildren()
+ .size() > 0;
+ }
+ if (e.getChild("Simple") != null) {
+ return e.getChild("Simple").getChildren().size() > 0;
+ }
+ if (e.getChild("Simple", MOBY_NS) != null) {
+ return e.getChild("Simple", MOBY_NS).getChildren().size() > 0;
+ }
+ return false;
+ }
+ } catch (MobyException e1) {
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @param xml
+ * the xml message to test whether or not there is stuff in the
+ * mobyData portion of a message.
+ * @return true if there is data, false otherwise.
+ */
+ public static boolean isThereData(String xml) {
+ try {
+ return isThereData(getDOMDocument(xml).getRootElement());
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public static void main(String[] args) throws MobyException {
+ String msg = "<moby:MOBY xmlns:moby=\"http://www.biomoby.org/moby\">\r\n"
+ + " <moby:mobyContent>\r\n"
+ + " <moby:mobyData moby:queryID=\"a2_+_s65_+_s165_+_s1290_a2_+_s65_+_s165_+_s1290_+_s1408_a0_+_s3_+_s1409\">\r\n"
+ + " <moby:Collection moby:articleName=\"alleles\">\r\n"
+ + " <moby:Simple>\r\n"
+ + " <Object xmlns=\"http://www.biomoby.org/moby\" namespace=\"DragonDB_Allele\" id=\"def-101\" />\r\n"
+ + " </moby:Simple>\r\n"
+ + " <moby:Simple>\r\n"
+ + " <Object xmlns=\"http://www.biomoby.org/moby\" namespace=\"DragonDB_Allele\" id=\"def-chl\" />\r\n"
+ + " </moby:Simple>\r\n"
+ + " <moby:Simple>\r\n"
+ + " <Object xmlns=\"http://www.biomoby.org/moby\" namespace=\"DragonDB_Allele\" id=\"def-gli\" />\r\n"
+ + " </moby:Simple>\r\n"
+ + " <moby:Simple>\r\n"
+ + " <Object xmlns=\"http://www.biomoby.org/moby\" namespace=\"DragonDB_Allele\" id=\"def-nic\" />\r\n"
+ + " </moby:Simple>\r\n"
+ + " <moby:Simple>\r\n"
+ + " <Object xmlns=\"http://www.biomoby.org/moby\" namespace=\"DragonDB_Allele\" id=\"def-23\" />\r\n"
+ + " </moby:Simple>\r\n"
+ + " </moby:Collection>\r\n"
+ + " </moby:mobyData>\r\n"
+ + " </moby:mobyContent>\r\n"
+ + "</moby:MOBY>";
+ Element inputElement = getDOMDocument(msg).getRootElement();
+ String queryID = XMLUtilities.getQueryID(inputElement);
+ Element[] simples = XMLUtilities.getSimplesFromCollection(inputElement);
+
+ ArrayList list = new ArrayList();
+ for (int j = 0; j < simples.length; j++) {
+ Element wrappedSimple = XMLUtilities
+ .createMobyDataElementWrapper(simples[j]);
+ wrappedSimple = XMLUtilities.renameSimple("Allele", "Object",
+ wrappedSimple);
+ wrappedSimple = XMLUtilities.setQueryID(wrappedSimple, queryID
+ + "_+_" + XMLUtilities.getQueryID(wrappedSimple));
+ list.add(XMLUtilities.extractMobyData(wrappedSimple));
+ }
+ }
+
+ /*
+ *
+ * @param current the Element that you would like to search @param name the
+ * name of the element that you would like to find @param list the list to
+ * put the elements that are found in @return a list containing the elements
+ * that are named name
+ */
+ private static List listChildren(Element current, String name, List list) {
+ if (list == null)
+ list = new ArrayList();
+ if (current.getName().equals(name))
+ list.add(current);
+ List children = current.getChildren();
+ Iterator iterator = children.iterator();
+ while (iterator.hasNext()) {
+ Element child = (Element) iterator.next();
+ if (child instanceof Element)
+ listChildren(child, name, list);
+ }
+ return list;
+ }
+
+ /**
+ *
+ * @param collectionName
+ * the name you would like the collection to be called
+ * @param simples2makeCollection
+ * the list of Elements to merge into a collection
+ * @return null if a collection wasnt made, otherwise a fully wrapped
+ * collection is returned.
+ * @throws MobyException
+ */
+ public static Element createCollectionFromListOfSimples(
+ String collectionName, List<Element> simples2makeCollection)
+ throws MobyException {
+ if (simples2makeCollection.size() > 0) {
+ // create a collection from the list of
+ // simples
+ Element mimCollection = new Element("Collection",
+ XMLUtilities.MOBY_NS);
+ for (Element simple : simples2makeCollection) {
+ Element theSimple = XMLUtilities.extractMobyData(simple);
+ if (theSimple.getChild("Simple") != null)
+ theSimple = theSimple.getChild("Simple");
+ else if (theSimple.getChild("Simple", XMLUtilities.MOBY_NS) != null)
+ theSimple = theSimple.getChild("Simple",
+ XMLUtilities.MOBY_NS);
+ mimCollection.addContent(theSimple.detach());
+ }
+ String mimQueryID = "merged_" + queryCount++;
+
+ mimCollection = XMLUtilities.createMobyDataElementWrapper(
+ mimCollection, mimQueryID, null);
+ mimCollection = XMLUtilities.renameCollection(collectionName,
+ mimCollection);
+ mimCollection = XMLUtilities.createMobyDataElementWrapper(
+ mimCollection, mimQueryID, null);
+ return mimCollection;
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/taverna-biomoby-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
new file mode 100644
index 0000000..7d50ca3
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
@@ -0,0 +1,3 @@
+net.sf.taverna.t2.activities.biomoby.BiomobyActivityHealthChecker
+net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityHealthChecker
+net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivityHealthChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context-osgi.xml b/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context-osgi.xml
new file mode 100644
index 0000000..449a31e
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context-osgi.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="biomobyActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+ <service ref="biomobyObjectActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+ <service ref="mobyParseDatatypeActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+
+ <service ref="biomobyActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+ <service ref="biomobyObjectActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+ <service ref="mobyParseDatatypeActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context.xml b/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context.xml
new file mode 100644
index 0000000..3fbeaaf
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/resources/META-INF/spring/biomoby-activity-context.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="biomobyActivityHealthChecker" class="net.sf.taverna.t2.activities.biomoby.BiomobyActivityHealthChecker" />
+ <bean id="biomobyObjectActivityHealthChecker" class="net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityHealthChecker" />
+ <bean id="mobyParseDatatypeActivityHealthChecker" class="net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivityHealthChecker" />
+
+ <bean id="biomobyActivityFactory" class="net.sf.taverna.t2.activities.biomoby.BiomobyActivityFactory" />
+ <bean id="biomobyObjectActivityFactory" class="net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityFactory" />
+ <bean id="mobyParseDatatypeActivityFactory" class="net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivityFactory" />
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthCheckerTest.java b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthCheckerTest.java
new file mode 100644
index 0000000..504fdc6
--- /dev/null
+++ b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthCheckerTest.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for BiomobyActivityHealthChecker.
+ *
+ */
+public class BiomobyActivityHealthCheckerTest {
+
+ private BiomobyActivity activity;
+
+ private BiomobyActivityHealthChecker activityHealthChecker;
+
+ @Before
+ public void setUp() throws Exception {
+ activity = new BiomobyActivity();
+ activityHealthChecker = new BiomobyActivityHealthChecker();
+ }
+
+ @Test
+ public void testCanHandle() {
+ assertFalse(activityHealthChecker.canVisit(null));
+ assertFalse(activityHealthChecker.canVisit(new Object()));
+ assertFalse(activityHealthChecker.canVisit(new AbstractActivity<Object>() {
+ public void configure(Object conf) throws ActivityConfigurationException {
+ }
+ public Object getConfiguration() {
+ return null;
+ }
+ }));
+ assertTrue(activityHealthChecker.canVisit(activity));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthCheckerTest.java b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthCheckerTest.java
new file mode 100644
index 0000000..403d744
--- /dev/null
+++ b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthCheckerTest.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for BiomobyActivityHealthChecker.
+ *
+ */
+public class BiomobyObjectActivityHealthCheckerTest {
+
+ private BiomobyActivity activity;
+
+ private BiomobyActivityHealthChecker activityHealthChecker;
+
+ @Before
+ public void setUp() throws Exception {
+ activity = new BiomobyActivity();
+ activityHealthChecker = new BiomobyActivityHealthChecker();
+ }
+
+ @Test
+ public void testCanHandle() {
+ assertFalse(activityHealthChecker.canVisit(null));
+ assertFalse(activityHealthChecker.canVisit(new Object()));
+ assertFalse(activityHealthChecker.canVisit(new AbstractActivity<Object>() {
+ public void configure(Object conf) throws ActivityConfigurationException {
+ }
+ public Object getConfiguration() {
+ return null;
+ }
+ }));
+ assertTrue(activityHealthChecker.canVisit(activity));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthCheckerTest.java b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthCheckerTest.java
new file mode 100644
index 0000000..30c8a1d
--- /dev/null
+++ b/taverna-biomoby-activity/src/test/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthCheckerTest.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit tests for BiomobyActivityHealthChecker.
+ *
+ */
+public class MobyParseDatatypeActivityHealthCheckerTest {
+
+ private BiomobyActivity activity;
+
+ private BiomobyActivityHealthChecker activityHealthChecker;
+
+ @Before
+ public void setUp() throws Exception {
+ activity = new BiomobyActivity();
+ activityHealthChecker = new BiomobyActivityHealthChecker();
+ }
+
+ @Test
+ public void testCanHandle() {
+ assertFalse(activityHealthChecker.canVisit(null));
+ assertFalse(activityHealthChecker.canVisit(new Object()));
+ assertFalse(activityHealthChecker.canVisit(new AbstractActivity<Object>() {
+ public void configure(Object conf) throws ActivityConfigurationException {
+ }
+ public Object getConfiguration() {
+ return null;
+ }
+ }));
+ assertTrue(activityHealthChecker.canVisit(activity));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-ncbi-activity-ui/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-ncbi-activity-ui/pom.xml b/taverna-ncbi-activity-ui/pom.xml
new file mode 100644
index 0000000..0a8a983
--- /dev/null
+++ b/taverna-ncbi-activity-ui/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.ui-activities</groupId>
+ <artifactId>ncbi-activity-ui</artifactId>
+ <name>Taverna 2 NCBI web service Activity UI</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>wsdl-activity</artifactId>
+ <version>${t2.activities.version}</version>
+ </dependency>
+
+ <!-- testing dependencies -->
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context-osgi.xml b/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context-osgi.xml
new file mode 100644
index 0000000..1c13381
--- /dev/null
+++ b/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context-osgi.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context.xml
----------------------------------------------------------------------
diff --git a/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context.xml b/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context.xml
new file mode 100644
index 0000000..861c878
--- /dev/null
+++ b/taverna-ncbi-activity-ui/src/main/resources/META-INF/spring/ncbi-activity-ui-context.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-ncbi-activity-ui/src/main/resources/ncbi_services
----------------------------------------------------------------------
diff --git a/taverna-ncbi-activity-ui/src/main/resources/ncbi_services b/taverna-ncbi-activity-ui/src/main/resources/ncbi_services
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-ncbi-activity-ui/src/main/resources/wsdl.png
----------------------------------------------------------------------
diff --git a/taverna-ncbi-activity-ui/src/main/resources/wsdl.png b/taverna-ncbi-activity-ui/src/main/resources/wsdl.png
new file mode 100644
index 0000000..f9fdae8
Binary files /dev/null and b/taverna-ncbi-activity-ui/src/main/resources/wsdl.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/pom.xml b/taverna-soaplab-activity-ui/pom.xml
new file mode 100644
index 0000000..737a13d
--- /dev/null
+++ b/taverna-soaplab-activity-ui/pom.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.ui-activities</groupId>
+ <artifactId>soaplab-activity-ui</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Taverna 2 Soaplab Activity UI</name>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>soaplab-activity</artifactId>
+ <version>${t2.activities.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-icons-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-palette-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>contextual-views-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-tools</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>edits-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>file-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>menu-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.axis</groupId>
+ <artifactId>com.springsource.org.apache.axis</artifactId>
+ <version>${axis.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.rpc</groupId>
+ <artifactId>com.springsource.javax.xml.rpc</artifactId>
+ <version>${xml.rpc.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository
+ </url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-soaplab-activity-ui.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/taverna/taverna-soaplab-activity-ui.git</developerConnection>
+ <url>https://github.com/taverna/taverna-soaplab-activity-ui/</url>
+ <tag>HEAD</tag>
+ </scm>
+
+</project>
+
[13/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigController.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigController.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigController.java
new file mode 100644
index 0000000..450b2ba
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigController.java
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryConfigController.java,v $
+ * Revision $Revision: 1.4 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:57 $
+ * by $Author: davidwithers $
+ * Created on 27-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice.config;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.config.event.QueryComponentEvent;
+import org.biomart.martservice.config.event.QueryComponentListener;
+import org.biomart.martservice.config.ui.QueryComponent;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Dataset;
+import org.biomart.martservice.query.Filter;
+import org.biomart.martservice.query.Query;
+import org.biomart.martservice.query.QueryListener;
+import org.ensembl.mart.lib.config.FilterDescription;
+
+/**
+ * Controls the interaction between graphical <code>QueryComponent</code>s
+ * and <code>Query</code>s.
+ *
+ * @author David Withers
+ */
+public class QueryConfigController {
+ private static Logger logger = Logger
+ .getLogger("org.biomart.martservice.config");
+
+ private static QueryListener queryListener = new QueryHandler();
+
+ private MartQuery martQuery;
+
+ private Query query;
+
+ private Map<String, Attribute> initialAttributeMap = new HashMap<String, Attribute>();
+
+ private Map<String, Filter> initialFilterMap = new HashMap<String, Filter>();
+
+ private Map<String, Attribute> nameToAttributeMap = new HashMap<String, Attribute>();
+
+ private Map <String, Filter> nameToFilterMap = new HashMap<String, Filter>();
+
+ private QueryComponentHandler queryComponenHandler = new QueryComponentHandler();
+
+ /**
+ * Constructs an instance of a <code>QueryConfigController</code>.
+ *
+ * @param martQuery
+ */
+ public QueryConfigController(MartQuery martQuery) {
+ this.martQuery = martQuery;
+ query = martQuery.getQuery();
+ query.addQueryListener(queryListener);
+
+ for (Attribute attribute : query.getAttributes()) {
+ initialAttributeMap.put(attribute.getQualifiedName(), attribute);
+ nameToAttributeMap.put(attribute.getQualifiedName(), attribute);
+ }
+ for (Filter filter : query.getFilters()) {
+ initialFilterMap.put(filter.getQualifiedName(), filter);
+ nameToFilterMap.put(filter.getQualifiedName(), filter);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#finalize()
+ */
+ protected void finalize() throws Throwable {
+ super.finalize();
+ query.removeQueryListener(queryListener);
+ }
+
+ /**
+ * Returns the <code>MartQuery</code> under control.
+ *
+ * @return the <code>MartQuery</code> under control
+ */
+ public MartQuery getMartQuery() {
+ return martQuery;
+ }
+
+ /**
+ * Removes a <code>QueryComponent</code> from the controller.
+ *
+ * @param queryComponent
+ * the <code>QueryComponent</code> to remove
+ */
+ public void deregister(QueryComponent queryComponent) {
+ queryComponent.removeQueryComponentListener(queryComponenHandler);
+ }
+
+ /**
+ * Registers a <code>QueryComponent</code> with the controller.
+ *
+ * If the <code>Query</code> already contains an <code>Attribute</code>
+ * or <code>Filter</code> with the corresponding name the
+ * <code>QueryComponent</code> is set as selected.
+ *
+ * @param queryComponent
+ * the <code>QueryComponent</code> to register
+ */
+ public void register(QueryComponent queryComponent) {
+ if (queryComponent.getType() == QueryComponent.ATTRIBUTE) {
+ getAttribute(queryComponent);
+
+ // if query already contains attribute then set the component as
+ // selected
+ if (initialAttributeMap.containsKey(queryComponent
+ .getQualifiedName())) {
+ queryComponent.setSelected(true);
+ }
+
+ } else if (queryComponent.getType() == QueryComponent.FILTER) {
+ Filter filter = getFilter(queryComponent);
+
+ String value = filter.getValue();
+ if (value != null) {
+ if (filter.isBoolean()) {
+ if ("excluded".equals(value)) {
+ queryComponent.setValue("excluded");
+ } else {
+ queryComponent.setValue("only");
+ }
+ } else {
+ queryComponent.setValue(value);
+ }
+ }
+
+ if (initialFilterMap.containsKey(queryComponent.getQualifiedName())) {
+ queryComponent.setSelected(true);
+ }
+ } else if (queryComponent.getType() == QueryComponent.LINK) {
+ Iterator<String> linkedDatasets = martQuery.getLinkedDatasets().iterator();
+ // only one linked dataset allowed for now
+ if (linkedDatasets.hasNext()) {
+ String dataset = linkedDatasets.next();
+ queryComponent.setName(dataset);
+ queryComponent.setValue(martQuery.getLink(dataset));
+ }
+ }
+
+ queryComponent.addQueryComponentListener(queryComponenHandler);
+
+ }
+
+ /**
+ * Returns the <code>Attribute</code> mapped to the
+ * <code>QueryComponent</code>. If no <code>Attribute</code> is mapped
+ * a new <code>Attribute</code> is created and added to the map.
+ *
+ * @param queryComponent
+ * @return
+ */
+ private Attribute getAttribute(QueryComponent queryComponent) {
+ String internalName = queryComponent.getQualifiedName();
+ Attribute attribute = null;
+ if (nameToAttributeMap.containsKey(internalName)) {
+ attribute = (Attribute) nameToAttributeMap.get(internalName);
+ } else {
+ attribute = new Attribute(queryComponent.getName());
+ if (queryComponent.getValue() != null) {
+ attribute.setAttributes(queryComponent.getValue());
+ }
+ nameToAttributeMap.put(internalName, attribute);
+ }
+ return attribute;
+ }
+
+ /**
+ * Returns the <code>Filter</code> mapped to the
+ * <code>QueryComponent</code>. If no <code>Filter</code> is mapped a
+ * new <code>Filter</code> is created and added to the map.
+ *
+ * @param queryComponent
+ * @return
+ */
+ private Filter getFilter(QueryComponent queryComponent) {
+ FilterDescription filterDescription = (FilterDescription) queryComponent
+ .getConfigObject();
+ String internalName = queryComponent.getQualifiedName();
+ Filter filter;
+ if (nameToFilterMap.containsKey(internalName)) {
+ filter = (Filter) nameToFilterMap.get(internalName);
+ } else {
+ if ("boolean".equals(filterDescription.getType())) {
+ if ("excluded".equals(queryComponent.getValue())) {
+ filter = new Filter(queryComponent.getName(), "excluded", true);
+ } else {
+ filter = new Filter(queryComponent.getName(), "only", true);
+ }
+ } else {
+ String defaultValue = filterDescription.getDefaultValue();
+ if (defaultValue == null
+ && !QueryConfigUtils.isNestedList(filterDescription)) {
+ // if there is no default value but there are options then
+ // choose the first option as the filter value
+// Option[] options = filterDescription.getOptions();
+// if (options != null && options.length > 0) {
+// defaultValue = options[0].getValue();
+// } else {
+ defaultValue = queryComponent.getValue();
+// }
+ }
+ filter = new Filter(queryComponent.getName(), defaultValue);
+ if ("id_list".equals(filterDescription.getType())) {
+ filter.setList(true);
+ }
+ }
+ nameToFilterMap.put(internalName, filter);
+ }
+ return filter;
+ }
+
+ class QueryComponentHandler implements QueryComponentListener {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#attributeAdded(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void attributeAdded(QueryComponentEvent event) {
+ Attribute attribute = (Attribute) nameToAttributeMap.get(event
+ .getDataset().getName()
+ + "." + event.getName());
+ synchronized (query) {
+ martQuery.addAttribute(event.getDataset().getName(), attribute);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#attributeRemoved(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void attributeRemoved(QueryComponentEvent event) {
+ Attribute attribute = (Attribute) nameToAttributeMap.get(event
+ .getDataset().getName()
+ + "." + event.getName());
+ synchronized (query) {
+ martQuery.removeAttribute(attribute);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterAdded(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterAdded(QueryComponentEvent event) {
+ Filter filter = (Filter) nameToFilterMap.get(event.getDataset()
+ .getName()
+ + "." + event.getName());
+ synchronized (query) {
+ martQuery.addFilter(event.getDataset().getName(), filter);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterRemoved(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterRemoved(QueryComponentEvent event) {
+ Filter filter = (Filter) nameToFilterMap.get(event.getDataset()
+ .getName()
+ + "." + event.getName());
+ synchronized (query) {
+ martQuery.removeFilter(filter);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterChanged(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterChanged(QueryComponentEvent event) {
+ Filter filter = (Filter) nameToFilterMap.get(event.getDataset()
+ .getName()
+ + "." + event.getName());
+ synchronized (query) {
+ filter.setValue(event.getValue());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.event.QueryComponentListener#linkAdded(org.biomart.martservice.config.event.QueryComponentEvent)
+ */
+ public void linkAdded(QueryComponentEvent event) {
+ martQuery.addLinkedDataset(event.getName(), event.getValue());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.event.QueryComponentListener#linkRemoved(org.biomart.martservice.config.event.QueryComponentEvent)
+ */
+ public void linkRemoved(QueryComponentEvent event) {
+ martQuery.removeLinkedDataset(event.getName());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.QueryComponentListener#linkChanged(org.biomart.martservice.config.QueryComponentEvent)
+ */
+ public void linkChanged(QueryComponentEvent event) {
+ martQuery.changeLinkedDataset(event.getName(), event.getValue());
+ }
+
+ }
+
+ static class QueryHandler implements QueryListener {
+
+ public void attributeAdded(Attribute attribute, Dataset dataset) {
+ logger.info("Attribute Added " + attribute.getQualifiedName());
+ }
+
+ public void attributeRemoved(Attribute attribute, Dataset dataset) {
+ logger.info("Attribute Removed " + attribute.getQualifiedName());
+ }
+
+ public void filterAdded(Filter filter, Dataset dataset) {
+ logger.info("Filter Added " + filter.getQualifiedName() + " "
+ + filter.getValue());
+ }
+
+ public void filterRemoved(Filter filter, Dataset dataset) {
+ logger.info("Filter Removed " + filter.getQualifiedName());
+ }
+
+ public void filterChanged(Filter filter, Dataset dataset) {
+ logger.info("Filter Changed " + filter.getQualifiedName() + " "
+ + filter.getValue());
+ }
+
+ public void formatterAdded(String formatter) {
+ logger.info("Formatter Added " + formatter);
+ }
+
+ public void formatterRemoved(String formatter) {
+ logger.info("Formatter Removed " + formatter);
+ }
+
+ public void formatterChanged(String formatter) {
+ logger.info("Formatter Changed to " + formatter);
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigUtils.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigUtils.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigUtils.java
new file mode 100644
index 0000000..2bc7d71
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/QueryConfigUtils.java
@@ -0,0 +1,598 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryConfigUtils.java,v $
+ * Revision $Revision: 1.3 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:57 $
+ * by $Author: davidwithers $
+ * Created on 30-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice.config;
+
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.border.EtchedBorder;
+
+import org.biomart.martservice.MartDataset;
+import org.biomart.martservice.MartService;
+import org.biomart.martservice.MartServiceException;
+import org.biomart.martservice.config.ui.QueryComponent;
+import org.ensembl.mart.lib.config.AttributeDescription;
+import org.ensembl.mart.lib.config.AttributePage;
+import org.ensembl.mart.lib.config.BaseNamedConfigurationObject;
+import org.ensembl.mart.lib.config.DatasetConfig;
+import org.ensembl.mart.lib.config.FilterDescription;
+import org.ensembl.mart.lib.config.Option;
+
+/**
+ * Utility class for configuration objects.
+ *
+ * @author David Withers
+ */
+public abstract class QueryConfigUtils {
+ public static final String LINE_END = System.getProperty("line.separator");
+
+ private static int DISPLAY_WIDTH = 35;
+
+ public static String splitSentence(String sentence) {
+ return splitSentence(sentence, DISPLAY_WIDTH);
+ }
+
+ public static String splitSentence(String sentence, int limit) {
+ StringBuffer sb = new StringBuffer();
+ sb.append("<html>");
+
+ int width = 0;
+ String[] split = sentence.split(" ");
+ for (int i = 0; i < split.length; i++) {
+ if (width == 0) {
+ sb.append(split[i]);
+ width += split[i].length();
+ } else if (width + split[i].length() + 1 > limit) {
+ sb.append("<br>");
+ sb.append(split[i]);
+ width = split[i].length();
+ } else {
+ sb.append(" ");
+ sb.append(split[i]);
+ width += split[i].length() + 1;
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Returns name truncated to DISPLAY_WIDTH.
+ *
+ * @param name
+ * @return
+ */
+ public static String truncateName(String name) {
+ if (name.length() > DISPLAY_WIDTH) {
+ return name.substring(0, DISPLAY_WIDTH);
+ } else {
+ return name;
+ }
+ }
+
+ public static List<String> getOutputFormats(AttributePage attributePage) {
+ List<String> outputFormats = new ArrayList<String>();
+
+ String[] formats = attributePage.getOutFormats().split(",");
+ for (int i = 0; i < formats.length; i++) {
+ outputFormats.add(formats[i]);
+ }
+ return outputFormats;
+ }
+
+ /**
+ * Returns true if filterDescription has no options.
+ *
+ * @param filterDescription
+ * @return true if filterDescription has no options
+ */
+ public static boolean isList(FilterDescription filterDescription) {
+ return filterDescription.getOptions().length > 0;
+ }
+
+ /**
+ * Returns true if filterDescription has options and at least one option
+ * also has options.
+ *
+ * @param filterDescription
+ * @return true if filterDescription has options and at least one option
+ * also has options
+ */
+ public static boolean isNestedList(FilterDescription filterDescription) {
+ Option[] options = filterDescription.getOptions();
+ for (int i = 0; i < options.length; i++) {
+ if (options[i].getOptions().length > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if filterDescription has options and the first option has a
+ * type equal to "boolean".
+ *
+ * @param filterDescription
+ * @return true if filterDescription has options and the first option has a
+ * type equal to "boolean"
+ */
+ public static boolean isBooleanList(FilterDescription filterDescription) {
+ Option[] options = filterDescription.getOptions();
+ if (options.length > 0) {
+ if ("boolean".equals(options[0].getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if filterDescription has options and the first option has a
+ * value equal to null.
+ *
+ * @param filterDescription
+ * @return true if filterDescription has options and the first option has a
+ * value equal to null
+ */
+ public static boolean isIdList(FilterDescription filterDescription) {
+ Option[] options = filterDescription.getOptions();
+ if (options.length > 0) {
+ if (options[0].getValue() == null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static Option[] fixOptionLength(Option[] options, int length) {
+ if (options.length > length) {
+ Option[] firstOptions = new Option[length];
+ Option[] otherOptions = new Option[options.length - (length - 1)];
+ for (int i = 0; i < length - 1; i++) {
+ firstOptions[i] = options[i];
+ fixOptionLength(options[i].getOptions(), length);
+ }
+ for (int i = length - 1; i < options.length; i++) {
+ otherOptions[i - (length - 1)] = options[i];
+ }
+ Option newOption = new Option();
+ newOption.setInternalName("more");
+ newOption.setDisplayName("more");
+ newOption.addOptions(fixOptionLength(otherOptions, length));
+ firstOptions[length - 1] = newOption;
+ return firstOptions;
+ } else {
+ return options;
+ }
+ }
+
+ public static Component getOptionButton(
+ FilterDescription filterDescription, QueryComponent queryComponent) {
+ JMenuBar menuBar = new JMenuBar();
+ menuBar.setBorder(new EtchedBorder());
+ JMenu menu = new JMenu("browse");
+ menu.setFont(menu.getFont().deriveFont(Font.PLAIN));
+ menuBar.add(menu);
+ Option[] options = fixOptionLength(filterDescription.getOptions(), 20);
+ for (int i = 0; i < options.length; i++) {
+ menu.add(getMenuItem(options[i], queryComponent));
+ }
+ return menuBar;
+ }
+
+ public static JMenuItem getMenuItem(final Option option,
+ final QueryComponent queryComponent) {
+ JMenuItem menuItem;
+
+ Option[] options = option.getOptions();
+ if (options.length > 0) {
+ JMenu menu = new JMenu(option.getDisplayName());
+ menu.setFont(menu.getFont().deriveFont(Font.PLAIN));
+ for (int i = 0; i < options.length; i++) {
+ menu.add(getMenuItem(options[i], queryComponent));
+ }
+ menuItem = menu;
+ } else {
+ menuItem = new JMenuItem(option.getDisplayName());
+ menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
+ menuItem.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ queryComponent.setValue(option.getValue());
+ }
+
+ });
+ }
+
+ return menuItem;
+ }
+
+ /**
+ * Returns the dataset referenced by a configuration object or null if the
+ * configuration object does not reference a dataset.
+ *
+ * @param martService
+ * the MartService to fetch the referenced dataset from
+ * @param referencedFromDataset
+ * the datset containing the configuration object
+ * @param bnco
+ * the configuration object
+ * @return the dataset referenced by a configuration object or null if the
+ * configuration object does not reference a dataset.
+ * @throws MartServiceException
+ * if and exception occurs while fetching the dataset
+ */
+ public static MartDataset getReferencedDataset(MartService martService,
+ MartDataset referencedFromDataset,
+ BaseNamedConfigurationObject bnco, String softwareVersion)
+ throws MartServiceException {
+ if ("0.5".equals(softwareVersion)) {
+ String pointerDataset = bnco.getAttribute("pointerDataset");
+ if (pointerDataset != null) {
+ return martService.getDataset(referencedFromDataset
+ .getVirtualSchema(), pointerDataset);
+ } else {
+ return null;
+ }
+ } else {
+ String[] splitName = bnco.getInternalName().split("\\.");
+ if (splitName.length > 1) {
+ return martService.getDataset(referencedFromDataset
+ .getVirtualSchema(), splitName[0]);
+ } else {
+ return null;
+ }
+ }
+ }
+
+ /**
+ * Returns the filter description referenced by the filter description.
+ *
+ * @param martService
+ * the MartService to fetch the referenced filter description
+ * from
+ * @param dataset
+ * the datset containing the referenced filter description
+ * @param filterDescription
+ * the filter description
+ * @return the filter description referenced by the filter description
+ * @throws MartServiceException
+ * if and exception occurs while fetching the filter description
+ */
+ public static FilterDescription getReferencedFilterDescription(
+ MartService martService, MartDataset dataset,
+ FilterDescription filterDescription, String softwareVersion)
+ throws MartServiceException {
+ if ("0.5".equals(softwareVersion)) {
+ String pointerFilter = filterDescription
+ .getAttribute("pointerFilter");
+ if (pointerFilter != null) {
+ return getReferencedFilterDescription(martService, dataset,
+ pointerFilter);
+ } else {
+ return null;
+ }
+ } else {
+ String[] splitName = filterDescription.getInternalName().split(
+ "\\.");
+ FilterDescription ref = getReferencedFilterDescription(martService,
+ dataset, splitName[1]);
+ return ref;
+ }
+ }
+
+ /**
+ * Returns the filter description referenced by the attribute description.
+ *
+ * @param martService
+ * the MartService to fetch the referenced filter description
+ * from
+ * @param dataset
+ * the datset containing the referenced filter description
+ * @param attributeDescription
+ * the attribute description
+ * @return the filter description referenced by the attribute description
+ * @throws MartServiceException
+ * if and exception occurs while fetching the filter description
+ */
+ public static FilterDescription getReferencedFilterDescription(
+ MartService martService, MartDataset dataset,
+ AttributeDescription attributeDescription, String softwareVersion)
+ throws MartServiceException {
+ if ("0.5".equals(softwareVersion)) {
+ String pointerFilter = attributeDescription
+ .getAttribute("pointerFilter");
+ if (pointerFilter != null) {
+ return getReferencedFilterDescription(martService, dataset,
+ pointerFilter);
+ } else {
+ return null;
+ }
+ } else {
+ String[] splitName = attributeDescription.getInternalName().split(
+ "\\.");
+ return getReferencedFilterDescription(martService, dataset,
+ splitName[2]);
+ }
+ }
+
+ public static FilterDescription getReferencedFilterDescription(
+ MartService martService, MartDataset dataset, String filterName)
+ throws MartServiceException {
+ FilterDescription referencedFilter = null;
+ DatasetConfig datasetConfig = martService.getDatasetConfig(dataset);
+ List<FilterDescription> filterDescriptions = datasetConfig.getAllFilterDescriptions();
+ for (FilterDescription filterDescription : filterDescriptions) {
+ if (filterName.equals(filterDescription.getInternalName())) {
+ if (!"true".equals(filterDescription.getHidden())) {
+ referencedFilter = filterDescription;
+ break;
+ }
+ }
+ }
+ return referencedFilter;
+ }
+
+ public static FilterDescription getReferencedFilterDescription(
+ AttributeDescription attributeDescription, String softwareVersion) {
+ FilterDescription filterDescription = new FilterDescription();
+ if ("0.5".equals(softwareVersion)) {
+ filterDescription.setInternalName(attributeDescription
+ .getInternalName());
+ filterDescription.setAttribute(attributeDescription
+ .getAttribute("pointerDataset"));
+ filterDescription.setAttribute(attributeDescription
+ .getAttribute("pointerFilter"));
+ filterDescription.setAttribute(attributeDescription
+ .getAttribute("pointerInterface"));
+ } else {
+ String[] splitName = attributeDescription.getInternalName().split(
+ "\\.");
+ filterDescription
+ .setInternalName(splitName[0] + "." + splitName[2]);
+ }
+ return filterDescription;
+ }
+
+ public static AttributeDescription getReferencedAttributeDescription(
+ MartService martService, MartDataset dataset,
+ AttributeDescription attributeDescription, String softwareVersion)
+ throws MartServiceException {
+ AttributeDescription referencedAttributeDescription = null;
+ String attributeName = null;
+ if ("0.5".equals(softwareVersion)) {
+ attributeName = attributeDescription
+ .getAttribute("pointerAttribute");
+ } else {
+ String internalName = attributeDescription.getInternalName();
+ String[] splitName = internalName.split("\\.");
+ if (splitName.length == 2) {
+ attributeName = splitName[1];
+ }
+ }
+ if (attributeName != null) {
+ DatasetConfig datasetConfig = martService.getDatasetConfig(dataset);
+ if (datasetConfig.containsAttributeDescription(attributeName)) {
+ referencedAttributeDescription = datasetConfig
+ .getAttributeDescriptionByInternalName(attributeName);
+ }
+ }
+ return referencedAttributeDescription;
+ }
+
+ /**
+ * Returns true if the internal name of the configuration object contains a
+ * '.' character.
+ *
+ * @param bnco
+ * the configuration object
+ * @return true if the internal name of the configuration object contains a
+ * '.' character
+ */
+ public static boolean isReference(BaseNamedConfigurationObject bnco,
+ String softwareVersion) {
+ if ("0.5".equals(softwareVersion)) {
+ return bnco.getAttribute("pointerDataset") != null
+ && (bnco.getAttribute("pointerAttribute") != null || bnco.getAttribute("pointerFilter") != null);
+ } else {
+ return bnco.getInternalName().indexOf(".") != -1;
+ }
+ }
+
+ /**
+ * Returns true if the internal name of the AttributeDescription has the
+ * format "[datasetName].[attributeName]".
+ *
+ * @param attributeDescription
+ * @return true if the internal name of the AttributeDescription has the
+ * format "[datasetName].[attributeName]"
+ */
+ public static boolean isAttributeReference(
+ AttributeDescription attributeDescription, String softwareVersion) {
+ if ("0.5".equals(softwareVersion)) {
+ return attributeDescription.getAttribute("pointerAttribute") != null;
+ } else {
+ return attributeDescription.getInternalName().split("\\.").length == 2;
+ }
+ }
+
+ /**
+ * Returns true if the internal name of the AttributeDescription has the
+ * format "[datasetName].filter.[filterName]".
+ *
+ * @param attributeDescription
+ * @return true if the internal name of the AttributeDescription has the
+ * format "[datasetName].filter.[filterName]"
+ */
+ public static boolean isFilterReference(
+ AttributeDescription attributeDescription, String softwareVersion) {
+ if ("0.5".equals(softwareVersion)) {
+ return attributeDescription.getAttribute("pointerFilter") != null;
+ } else {
+ return attributeDescription.getInternalName().split("\\.").length == 3;
+ }
+ }
+
+// /**
+// * Returns the qualified name of the AttributeDescription in the format
+// * "[datasetName].[attributeName]".
+// *
+// * @param dataset
+// * @param attributeDescription
+// * @return true if the qualified name of the AttributeDescription in the
+// * format "[datasetName].[attributeName]"
+// */
+// public static String getQualifiedName(MartDataset dataset,
+// AttributeDescription attributeDescription, String softwareVersion) {
+// if ("0.5".equals(softwareVersion)) {
+// if (isAttributeReference(attributeDescription, softwareVersion)) {
+// return attributeDescription.getAttribute("pointerDataset")
+// + "."
+// + attributeDescription.getAttribute("pointerAttribute");
+// } else if (isFilterReference(attributeDescription, softwareVersion)) {
+// return attributeDescription.getAttribute("pointerDataset")
+// + "."
+// + attributeDescription.getAttribute("pointerFilter");
+// } else {
+// return dataset.getName()
+// + attributeDescription.getInternalName();
+// }
+// } else {
+// if (isAttributeReference(attributeDescription, softwareVersion)) {
+// return attributeDescription.getInternalName();
+// } else if (isFilterReference(attributeDescription, softwareVersion)) {
+// String[] splitName = attributeDescription.getInternalName()
+// .split("\\.");
+// return splitName[0] + "." + splitName[2];
+// } else {
+// return dataset.getName()
+// + attributeDescription.getInternalName();
+// }
+// }
+// }
+
+ public static String csvToValuePerLine(String csv) {
+ StringBuffer list = new StringBuffer();
+
+ String[] splitString = csv.split(",");
+ for (int i = 0; i < splitString.length; i++) {
+ if (i > 0) {
+ list.append(LINE_END);
+ }
+ list.append(splitString[i].trim());
+ }
+
+ return list.toString();
+ }
+
+ public static String valuePerLineToCsv(String list) {
+ return list.trim().replaceAll("\\s", ",");
+ }
+
+ public static List<String> csvToList(String csv) {
+ List<String> list = new ArrayList<String>();
+
+ String[] splitString = csv.split(",");
+ for (int i = 0; i < splitString.length; i++) {
+ list.add(splitString[i].trim());
+ }
+
+ return list;
+ }
+
+ /**
+ * Converts a List of objects to a comma separated string of the objects'
+ * string representations in the order given by the List's iterator. For
+ * example:
+ *
+ * <blockquote>
+ *
+ * <pre>
+ * List list = Arrays.toList(new String[] {"one", "two", "three"};
+ * System.out.println(listToCsv(list));
+ * </pre>
+ *
+ * </blockquote> would return the string "one,two,three".
+ *
+ * @param list
+ * @return a List of objects to a comma separated string of the object's
+ * string representations
+ */
+ public static String listToCsv(List<?> list) {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
+ sb.append(iter.next().toString());
+ if (iter.hasNext()) {
+ sb.append(',');
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns true iff the 'display' or 'hidden' value of the configuration
+ * object is not "true".
+ *
+ * @param bnco
+ * the configuration object
+ * @return true iff the 'display' or 'hidden' value of configuration object
+ * is "true"
+ */
+ public static boolean display(BaseNamedConfigurationObject bnco) {
+ boolean display = true;
+ String hideDisplay = bnco.getDisplay();
+ if (hideDisplay != null) {
+ if (hideDisplay.equals("true")) {
+ display = false;
+ }
+ } else {
+ String hidden = bnco.getHidden();
+ if (hidden != null) {
+ if (hidden.equals("true")) {
+ display = false;
+ }
+ }
+ }
+ return display;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentAdapter.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentAdapter.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentAdapter.java
new file mode 100644
index 0000000..201cc1d
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentAdapter.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryComponentAdapter.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:06 $
+ * by $Author: davidwithers $
+ * Created on 04-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.config.event;
+
+/**
+ * An abstract adapter class for receiving <code>QueryComponent</code> events.
+ * The methods in this class are empty. This class exists as convenience for
+ * creating listener objects.
+ *
+ * @author David Withers
+ */
+public class QueryComponentAdapter implements QueryComponentListener {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#attributeAdded(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void attributeAdded(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#attributeRemoved(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void attributeRemoved(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterAdded(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterAdded(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterRemoved(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterRemoved(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentListener#filterChanged(org.embl.ebi.escience.scuflworkers.biomartservice.config.QueryComponentEvent)
+ */
+ public void filterChanged(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.event.QueryComponentListener#linkAdded(org.biomart.martservice.config.event.QueryComponentEvent)
+ */
+ public void linkAdded(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.event.QueryComponentListener#linkRemoved(org.biomart.martservice.config.event.QueryComponentEvent)
+ */
+ public void linkRemoved(QueryComponentEvent event) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.biomart.martservice.config.QueryComponentListener#linkChanged(org.biomart.martservice.config.QueryComponentEvent)
+ */
+ public void linkChanged(QueryComponentEvent event) {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentEvent.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentEvent.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentEvent.java
new file mode 100644
index 0000000..6fc5d18
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentEvent.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryComponentEvent.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:06 $
+ * by $Author: davidwithers $
+ * Created on 03-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.config.event;
+
+import java.util.EventObject;
+
+import org.biomart.martservice.MartDataset;
+
+/**
+ * An event which indicates that a <code>QueryComponent</code> has been
+ * selected, deselected or its value has been modified.
+ *
+ * @author David Withers
+ */
+public class QueryComponentEvent extends EventObject {
+ private static final long serialVersionUID = -7576317475836030298L;
+
+ private String name;
+
+ private MartDataset dataset;
+
+ private String value;
+
+ /**
+ * Constructs a new <code>QueryComponentEvent</code> instance.
+ *
+ * @param source
+ * the source of the event
+ * @param name
+ * the name of the attribute or filter affected by this event
+ * @param dataset
+ * the dataset containing the attribute or filter affected by
+ * this event
+ */
+ public QueryComponentEvent(Object source, String name, MartDataset dataset) {
+ this(source, name, dataset, null);
+ }
+
+ /**
+ * Constructs a new <code>QueryComponentEvent</code> instance.
+ *
+ * @param source
+ * the source of the event
+ * @param name
+ * the name of the attribute or filter affected by this event
+ * @param dataset
+ * the dataset containing the attribute or filter affected by
+ * this event
+ * @param value
+ * the value of the filter affected by this event
+ */
+ public QueryComponentEvent(Object source, String name, MartDataset dataset,
+ String value) {
+ super(source);
+ this.name = name;
+ this.dataset = dataset;
+ this.value = value;
+ }
+
+ /**
+ * Returns the name of the attribute or filter affected by this event.
+ *
+ * @return the name of the attribute or filter affected by this event.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the dataset containing the attribute or filter affected by this
+ * event.
+ *
+ * @return the dataset containing the attribute or filter affected by this
+ * event.
+ */
+ public MartDataset getDataset() {
+ return dataset;
+ }
+
+ /**
+ * Returns the value of the filter affected by this event.
+ *
+ * @return the value of the filter affected by this event.
+ */
+ public String getValue() {
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentListener.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentListener.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentListener.java
new file mode 100644
index 0000000..af63326
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/event/QueryComponentListener.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryComponentListener.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:06 $
+ * by $Author: davidwithers $
+ * Created on 03-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.config.event;
+
+import java.util.EventListener;
+
+/**
+ * The listener interface for receiving QueryComponent events.
+ *
+ * @author David Withers
+ */
+public interface QueryComponentListener extends EventListener {
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for an attribute is
+ * selected.
+ *
+ * @param event the query component event
+ */
+ public void attributeAdded(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for an attribute is
+ * deselected.
+ *
+ * @param event the query component event
+ */
+ public void attributeRemoved(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a filter is selected.
+ *
+ * @param event the query component event
+ */
+ public void filterAdded(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a filter is deselected.
+ *
+ * @param event the query component event
+ */
+ public void filterRemoved(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a filter is changed.
+ *
+ * @param event the query component event
+ */
+ public void filterChanged(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a link is selected.
+ *
+ * @param event the query component event
+ */
+ public void linkAdded(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a link is deselected.
+ *
+ * @param event the query component event
+ */
+ public void linkRemoved(QueryComponentEvent event);
+
+ /**
+ * Invoked when a <code>QueryComponent</code> for a dataset link id is
+ * changed.
+ *
+ * @param event the query component event
+ */
+ public void linkChanged(QueryComponentEvent event);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ConfigDisplayObject.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ConfigDisplayObject.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ConfigDisplayObject.java
new file mode 100644
index 0000000..89820d3
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ConfigDisplayObject.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: ConfigDisplayObject.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:09 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.Component;
+
+import org.ensembl.mart.lib.config.BaseNamedConfigurationObject;
+
+/**
+ * An object containing a configuration object and it's graphical component.
+ *
+ * @author David Withers
+ */
+public class ConfigDisplayObject {
+ private BaseNamedConfigurationObject configObject;
+
+ private Component component;
+
+ /**
+ * Constructs an instance of a <code>ConfigDisplayObject</code> with the
+ * specified configuration object and a <code>null</code> component.
+ *
+ * @param configObject
+ * the configuration object; must not be <code>null</code>
+ */
+ public ConfigDisplayObject(BaseNamedConfigurationObject configObject) {
+ this(configObject, null);
+ }
+
+ /**
+ * Constructs an instance of a <code>ConfigDisplayObject</code> with the
+ * specified configuration object and component.
+ *
+ * @param configObject
+ * the configuration object; must not be <code>null</code>
+ * @param component
+ * the component
+ */
+ public ConfigDisplayObject(BaseNamedConfigurationObject configObject,
+ Component component) {
+ if (configObject == null) {
+ throw new IllegalArgumentException(
+ "Parameter 'configObject' must not be null");
+ }
+ this.configObject = configObject;
+ this.component = component;
+ }
+
+ /**
+ * Returns the display name.
+ *
+ * @return the display name
+ */
+ public String getDisplayName() {
+ return configObject.getDisplayName();
+ }
+
+ /**
+ * Returns the internal name.
+ *
+ * @return the internal name
+ */
+ public String getInternalName() {
+ return configObject.getInternalName();
+ }
+
+ /**
+ * Returns the display name.
+ *
+ * @return the display name
+ */
+ public String toString() {
+ return getDisplayName();
+ }
+
+ /**
+ * Returns the configuration object.
+ *
+ * @return the configuration object
+ */
+ public BaseNamedConfigurationObject getConfigObject() {
+ return configObject;
+ }
+
+ /**
+ * Returns the component.
+ *
+ * @return the component.
+ */
+ public Component getComponent() {
+ return component;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ExpandableBox.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ExpandableBox.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ExpandableBox.java
new file mode 100644
index 0000000..d5ff0dd
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/ExpandableBox.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: ExpandableBox.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:56 $
+ * by $Author: davidwithers $
+ * Created on Jun 22, 2007
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.Timer;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+
+/**
+ * A component that when collapsed only shows a title and when expanded shows
+ * the title and contained components.
+ *
+ * @author David Withers
+ *
+ */
+public class ExpandableBox extends JPanel {
+ private static final long serialVersionUID = -5678399632577606442L;
+
+ private JButton expandButton;
+
+ private JPanel labelBox;
+
+ private boolean expanded = true;
+
+ private boolean animated = false;
+
+ private Timer timer = new Timer(1, null);
+
+ private Dimension minSize;
+
+ private Dimension maxSize;
+
+ private int height;
+
+ private final int increment = 10;
+
+ private ActionListener openAction = new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ if (height <= maxSize.height) {
+ setPreferredSize(new Dimension(maxSize.width, height));
+ revalidate();
+ repaint();
+ height += increment;
+ } else {
+ timer.removeActionListener(this);
+ timer.stop();
+ setPreferredSize(new Dimension(maxSize.width, maxSize.height));
+ revalidate();
+ repaint();
+ }
+ }
+ };
+
+ private ActionListener closeAction = new ActionListener() {
+ public void actionPerformed(ActionEvent evt) {
+ if (height >= minSize.height) {
+ setPreferredSize(new Dimension(minSize.width, height));
+ revalidate();
+ repaint();
+ height -= increment;
+ } else {
+ timer.removeActionListener(this);
+ timer.stop();
+ height = minSize.height;
+ setPreferredSize(new Dimension(minSize.width, height));
+ revalidate();
+ repaint();
+ }
+ }
+ };
+
+ public ExpandableBox(Component titleComponent, Color backgroundColor,
+ Color borderColor) {
+ this(titleComponent, backgroundColor, borderColor, new Insets(10, 10,
+ 10, 10), false);
+ }
+
+ public ExpandableBox(Component titleComponent, Color backgroundColor,
+ Color borderColor, Insets borderInsets) {
+ this(titleComponent, backgroundColor, borderColor, borderInsets, false);
+ }
+
+ public ExpandableBox(Component titleComponent, Color backgroundColor,
+ Color borderColor, boolean animated) {
+ this(titleComponent, backgroundColor, borderColor, new Insets(10, 10,
+ 10, 10), animated);
+ }
+
+ public ExpandableBox(Component titleComponent, Color backgroundColor,
+ Color borderColor, Insets borderInsets, boolean animated) {
+ this.animated = animated;
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setBackground(backgroundColor);
+ setBorder(new CompoundBorder(new LineBorder(borderColor, 1),
+ new EmptyBorder(borderInsets)));
+
+ labelBox = new JPanel();
+ labelBox.setLayout(new BoxLayout(labelBox, BoxLayout.X_AXIS));
+ labelBox.setBackground(backgroundColor);
+
+ expandButton = new JButton(MartServiceIcons.getIcon("contract"));
+ expandButton.setActionCommand("contract");
+ expandButton.setBackground(backgroundColor);
+ expandButton.setBorder(new EmptyBorder(0, 0, 0, 0));
+ expandButton.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ if ("contract".equals(e.getActionCommand())) {
+ setExpanded(false);
+ } else {
+ setExpanded(true);
+ }
+ }
+
+ });
+ labelBox.add(expandButton);
+ labelBox.add(Box.createHorizontalStrut(5));
+ labelBox.add(titleComponent);
+ labelBox.add(Box.createHorizontalGlue());
+ add(labelBox);
+ minSize = getPreferredSize();
+ }
+
+ public void setExpanded(boolean expanded) {
+ if (maxSize == null || maxSize.height <= minSize.height) {
+ maxSize = getLayout().preferredLayoutSize(this);
+ }
+ if (this.expanded != expanded) {
+ this.expanded = expanded;
+ if (expanded) {
+ expandButton.setIcon(MartServiceIcons.getIcon("contract"));
+ expandButton.setActionCommand("contract");
+ if (animated) {
+ timer.stop();
+ timer.removeActionListener(closeAction);
+ timer.addActionListener(openAction);
+ timer.start();
+ } else {
+ setPreferredSize(new Dimension(maxSize.width,
+ maxSize.height));
+ }
+ } else {
+ expandButton.setIcon(MartServiceIcons.getIcon("expand"));
+ expandButton.setActionCommand("expand");
+ if (animated) {
+ timer.stop();
+ timer.removeActionListener(openAction);
+ timer.addActionListener(closeAction);
+ timer.start();
+ } else {
+ setPreferredSize(new Dimension(minSize.width,
+ minSize.height));
+ }
+ }
+ revalidate();
+ repaint();
+ }
+ expandButton.setSelected(expanded);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceIcons.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceIcons.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceIcons.java
new file mode 100644
index 0000000..15f294a
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MartServiceIcons.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceIcons.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:56 $
+ * by $Author: davidwithers $
+ * Created on 24-Aug-2006
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+/**
+ *
+ * @author witherd5
+ */
+public class MartServiceIcons {
+ private static Map<String, Icon> nameToIcon = new HashMap<String, Icon>();
+
+ private static final String imageLocation = "org/biomart/martservice/config/ui/";
+
+ static {
+ ClassLoader loader = MartServiceQueryConfigUIFactory.class
+ .getClassLoader();
+ if (loader == null) {
+ loader = Thread.currentThread().getContextClassLoader();
+ }
+
+ nameToIcon.put("gene_schematic", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic.gif")));
+ nameToIcon.put("gene_schematic_3utr", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_3utr.gif")));
+ nameToIcon.put("gene_schematic_5utr", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_5utr.gif")));
+ nameToIcon.put("gene_schematic_cdna", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_cdna.gif")));
+ nameToIcon.put("gene_schematic_coding_gene_flank", new ImageIcon(loader
+ .getResource(imageLocation
+ + "gene_schematic_coding_gene_flank.gif")));
+ nameToIcon.put("gene_schematic_coding_transcript_flank", new ImageIcon(
+ loader.getResource(imageLocation
+ + "gene_schematic_coding_transcript_flank.gif")));
+ nameToIcon.put("gene_schematic_coding", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_coding.gif")));
+ nameToIcon.put("gene_schematic_gene_exon_intron", new ImageIcon(loader
+ .getResource(imageLocation
+ + "gene_schematic_gene_exon_intron.gif")));
+ nameToIcon.put("gene_schematic_gene_exon", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_gene_exon.gif")));
+ nameToIcon.put("gene_schematic_gene_flank", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_gene_flank.gif")));
+ nameToIcon.put("gene_schematic_peptide", new ImageIcon(loader
+ .getResource(imageLocation + "gene_schematic_peptide.gif")));
+ nameToIcon.put("gene_schematic_transcript_exon_intron", new ImageIcon(
+ loader.getResource(imageLocation
+ + "gene_schematic_transcript_exon_intron.gif")));
+ nameToIcon.put("gene_schematic_transcript_exon", new ImageIcon(
+ loader.getResource(imageLocation
+ + "gene_schematic_transcript_exon.gif")));
+ nameToIcon.put("gene_schematic_transcript_flank", new ImageIcon(loader
+ .getResource(imageLocation
+ + "gene_schematic_transcript_flank.gif")));
+ nameToIcon.put("contract", new ImageIcon(loader
+ .getResource(imageLocation
+ + "contract.gif")));
+ nameToIcon.put("expand", new ImageIcon(loader
+ .getResource(imageLocation
+ + "expand.gif")));
+ }
+
+ public static Icon getIcon(String name) {
+ return (Icon) nameToIcon.get(name);
+ }
+
+}
[15/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivity.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivity.java b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivity.java
new file mode 100644
index 0000000..7e87939
--- /dev/null
+++ b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivity.java
@@ -0,0 +1,351 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartServiceException;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.biomart.martservice.ResultReceiver;
+import org.biomart.martservice.ResultReceiverException;
+import org.biomart.martservice.config.QueryConfigUtils;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Dataset;
+import org.biomart.martservice.query.Filter;
+import org.biomart.martservice.query.Query;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * An Activity providing Biomart functionality.
+ *
+ * @author David Withers
+ */
+public class BiomartActivity extends AbstractAsynchronousActivity<JsonNode> {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/biomart";
+
+ static boolean STREAM_RESULTS = true;
+
+ private static Logger logger = Logger.getLogger(BiomartActivity.class);
+
+ private JsonNode json;
+
+ private MartQuery biomartQuery;
+
+ @Override
+ public void configure(JsonNode json)
+ throws ActivityConfigurationException {
+ this.json = json;
+ String martQueryText = json.get("martQuery").asText();
+ SAXBuilder builder = new SAXBuilder();
+ try {
+ Document document = builder.build(new StringReader(martQueryText));
+ biomartQuery = MartServiceXMLHandler.elementToMartQuery(document.getRootElement(), null);
+ } catch (JDOMException | IOException e) {
+ throw new ActivityConfigurationException(e);
+ }
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return json;
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ public void run() {
+ final ReferenceService referenceService = callback.getContext().getReferenceService();
+
+ final Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();
+
+ try {
+ // Get a query including data source etc, creating
+ // a copy so that any filter value settings are not
+ // overwritten by input values
+ biomartQuery.calculateLinks();
+ Query query = new Query(biomartQuery.getQuery());
+
+ // Configure any filters
+ List<Filter> filters = query.getFilters();
+ for (Filter filter : filters) {
+ String name = filter.getQualifiedName();
+ if (data.containsKey(name + "_filter")) {
+ Object filterValue = referenceService.renderIdentifier(data
+ .get(name + "_filter"), String.class, callback.getContext());
+ if (filterValue instanceof String) {
+ filter.setValue((String) filterValue);
+ } else if (filterValue instanceof List) {
+ List<?> idList = (List<?>) filterValue;
+ filter.setValue(QueryConfigUtils
+ .listToCsv(idList));
+ }
+ }
+ }
+
+ if (biomartQuery.getQuery().getFormatter() == null) {
+ if (STREAM_RESULTS) {
+ final List<Attribute> attributes = biomartQuery
+ .getAttributesInLinkOrder();
+ final Map<String, List<T2Reference>> outputLists = new HashMap<String, List<T2Reference>>();
+ for (Attribute attribute : attributes) {
+ outputLists.put(attribute.getQualifiedName(),
+ new ArrayList<T2Reference>());
+ }
+
+ biomartQuery.getMartService().executeQuery(query,
+ new ResultReceiver() {
+
+ public void receiveResult(
+ Object[] resultLine, long index) throws ResultReceiverException {
+ Map<String, T2Reference> partialOutputData = new HashMap<String, T2Reference>();
+ for (int i = 0; i < resultLine.length; i++) {
+ Attribute attribute = attributes
+ .get(i);
+ String outputName = attribute
+ .getQualifiedName();
+ Integer outputDepth = getOutputPortDepth(outputName);
+ if (outputDepth == null) {
+ logger.warn("Skipping unknown output port " + outputName);
+ continue;
+ }
+ try {
+ T2Reference data = referenceService
+ .register(resultLine[i], outputDepth - 1, true, callback.getContext());
+ partialOutputData.put(
+ outputName, data);
+ outputLists.get(outputName)
+ .add((int) index, data);
+ } catch (ReferenceServiceException e) {
+ throw new ResultReceiverException(e);
+// callback.fail("Failure when calling the reference service", e);
+ }
+ }
+ callback.receiveResult(
+ partialOutputData,
+ new int[] { (int) index });
+ }
+
+ public void receiveError(String message,
+ long index) throws ResultReceiverException {
+ Map<String, T2Reference> partialOutputData = new HashMap<String, T2Reference>();
+ for (Attribute attribute : attributes) {
+ String outputName = attribute
+ .getQualifiedName();
+ Integer outputDepth = getOutputPortDepth(outputName);
+ if (outputDepth == null) {
+ logger.warn("Skipping unknown output port " + outputName);
+ continue;
+ }
+ try {
+ T2Reference error = referenceService.getErrorDocumentService()
+ .registerError(message, outputDepth - 1, callback.getContext()).getId();
+ partialOutputData.put(
+ outputName, error);
+ outputLists.get(outputName)
+ .add((int) index, error);
+ } catch (ReferenceServiceException e) {
+ throw new ResultReceiverException(e);
+// callback.fail("Failure when calling the reference service", e);
+ }
+ }
+ callback.receiveResult(
+ partialOutputData,
+ new int[] { (int) index });
+ }
+
+ });
+
+ for (Attribute attribute : attributes) {
+ String outputName = attribute
+ .getQualifiedName();
+ Integer outputDepth = getOutputPortDepth(outputName);
+ if (outputDepth == null) {
+ logger.warn("Skipping unknown output port " + outputName);
+ continue;
+ }
+ outputData.put(outputName, referenceService.register(
+ outputLists.get(outputName),
+ outputDepth, true, callback.getContext()));
+ }
+
+ } else {
+ // shouldn't need to reorder attributes for MartJ
+ // 0.5
+ Object[] resultList = biomartQuery.getMartService()
+ .executeQuery(query);
+ List<Attribute> attributes = biomartQuery
+ .getAttributesInLinkOrder();
+ assert resultList.length == attributes.size();
+ for (int i = 0; i < resultList.length; i++) {
+ Attribute attribute = attributes.get(i);
+ String outputName = attribute
+ .getQualifiedName();
+ Integer outputDepth = getOutputPortDepth(outputName);
+ if (outputDepth == null) {
+ logger.warn("Skipping unknown output port " + outputName);
+ } else {
+ outputData.put(outputName, referenceService.register(
+ resultList[i], outputDepth, true, callback.getContext()));
+ }
+ }
+ }
+ } else {
+ Object[] resultList = biomartQuery.getMartService()
+ .executeQuery(query);
+ assert resultList.length == 1;
+ Dataset dataset = biomartQuery.getQuery().getDatasets()
+ .get(0);
+ String outputName = dataset.getName();
+ Integer outputDepth = getOutputPortDepth(outputName);
+ if (outputDepth == null) {
+ logger.warn("Skipping unknown output port " + outputName);
+ } else {
+ outputData.put(outputName, referenceService.register(
+ resultList[0], outputDepth, true, callback.getContext()));
+ }
+ }
+
+ callback.receiveResult(outputData, new int[0]);
+ } catch (MartServiceException e) {
+ callback.fail("Failure calling biomart", e);
+ } catch (ReferenceServiceException e) {
+ callback.fail("Failure when calling the reference service", e);
+ } catch (ResultReceiverException e) {
+ callback.fail("Failure when receiving a result from biomart", e);
+ }
+ }
+
+ });
+
+ }
+
+ private Integer getOutputPortDepth(String portName) {
+ for (ActivityOutputPort port : getOutputPorts()) {
+ if (port.getName().equals(portName)) {
+ return port.getDepth();
+ }
+ }
+ return null;
+ }
+
+// private void buildInputPorts(List<Edit<?>> editList) {
+// Map<String, ActivityInputPort> newInputMap = new HashMap<String, ActivityInputPort>();
+// List<Filter> filters = biomartQuery.getQuery().getFilters();
+// // Create new input ports corresponding to filters
+// for (Filter filter : filters) {
+// String name = filter.getQualifiedName() + "_filter";
+// if (inputMap.containsKey(name)) {
+// newInputMap.put(name, inputMap.remove(name));
+// } else {
+// ActivityInputPort inputPort = null;
+// if (filter.isList()) {
+// inputPort = edits.createActivityInputPort(name, 1, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+// String.class);
+// } else {
+// inputPort = edits.createActivityInputPort(name, 0, true,
+// new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+// String.class);
+// }
+// newInputMap.put(name, inputPort);
+// editList.add(edits.getAddActivityInputPortEdit(this, inputPort));
+// editList.add(createAddMimeTypeAnnotationEdit(inputPort, "text/plain"));
+// }
+// }
+// //remove any ports still left in the map
+// for (ActivityInputPort inputPort : inputMap.values()) {
+// editList.add(edits.getRemoveActivityInputPortEdit(this, inputPort));
+// }
+// inputMap = newInputMap;
+// }
+
+// private void buildOutputPorts(List<Edit<?>> editList) {
+// Map<String, ActivityOutputPort> newOutputMap = new HashMap<String, ActivityOutputPort>();
+// Query query = biomartQuery.getQuery();
+// List<Attribute> attributes = query.getAttributes();
+// String formatter = query.getFormatter();
+// if (formatter == null) {
+// // Create new output ports corresponding to attributes
+// for (Attribute attribute : attributes) {
+// String name = attribute.getQualifiedName();
+// if (outputMap.containsKey(name)) {
+// newOutputMap.put(name, outputMap.remove(name));
+// } else {
+// ActivityOutputPort outputPort = null;
+// if (attribute.getAttributes() != null) {
+// outputPort = edits.createActivityOutputPort(name, 2, STREAM_RESULTS?1:2);
+// } else {
+// outputPort = edits.createActivityOutputPort(name, 1, STREAM_RESULTS?0:1);
+// }
+// newOutputMap.put(name, outputPort);
+// editList.add(edits.getAddActivityOutputPortEdit(this, outputPort));
+// editList.add(createAddMimeTypeAnnotationEdit(outputPort, "text/plain"));
+// }
+// }
+// } else if (attributes.size() > 0) {
+// // create one port using the dataset name
+// Attribute attribute = attributes.get(0);
+// String name = attribute.getContainingDataset().getName();
+// if (outputMap.containsKey(name)) {
+// newOutputMap.put(name, outputMap.remove(name));
+// } else {
+// ActivityOutputPort outputPort = edits.createActivityOutputPort(name, 0, 0);
+// newOutputMap.put(name, outputPort);
+// editList.add(edits.getAddActivityOutputPortEdit(this, outputPort));
+// editList.add(createAddMimeTypeAnnotationEdit(outputPort, "text/plain"));
+// }
+// }
+// //remove any ports still left in the map
+// for (ActivityOutputPort outputPort : outputMap.values()) {
+// editList.add(edits.getRemoveActivityOutputPortEdit(this, outputPort));
+// }
+// outputMap = newOutputMap;
+// }
+
+// private Edit<?> createAddMimeTypeAnnotationEdit(Annotated<?> annotated, String type) {
+// MimeType mimeType = new MimeType();
+// mimeType.setText(type);
+// return edits.getAddAnnotationChainEdit(annotated, mimeType);
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityConfigurationBean.java b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityConfigurationBean.java
new file mode 100644
index 0000000..91cc323
--- /dev/null
+++ b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityConfigurationBean.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+import org.jdom.Element;
+
+/**
+ * Biomart configuration.
+ *
+ * @author David Withers
+ */
+@ConfigurationBean(uri = BiomartActivity.URI + "#Config")
+public class BiomartActivityConfigurationBean {
+
+ private Element martQuery;
+
+ public Element getMartQuery() {
+ return martQuery;
+ }
+
+ @ConfigurationProperty(name = "martQuery", label = "Mart Query", description = "Biomart query in XML")
+ public void setMartQuery(Element martQuery) {
+ this.martQuery = martQuery;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactory.java b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactory.java
new file mode 100644
index 0000000..4aaf043
--- /dev/null
+++ b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactory.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Filter;
+import org.biomart.martservice.query.Query;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * An {@link ActivityFactory} for creating <code>BiomartActivity</code>.
+ *
+ * @author David Withers
+ */
+public class BiomartActivityFactory implements ActivityFactory {
+
+ private static Logger logger = Logger.getLogger(BiomartActivityFactory.class);
+
+ private Edits edits;
+ private SAXBuilder builder = new SAXBuilder();
+
+ @Override
+ public BiomartActivity createActivity() {
+ return new BiomartActivity();
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(BiomartActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration) {
+ Set<ActivityInputPort> inputPorts = new HashSet<>();
+ try {
+ Query query = getQuery(configuration);
+ for (Filter filter : query.getFilters()) {
+ String name = filter.getQualifiedName() + "_filter";
+ inputPorts.add(edits.createActivityInputPort(name, filter.isList() ? 1 : 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(), String.class));
+ }
+ } catch (JDOMException | IOException e) {
+ logger.warn("Error caluculating input ports from BioMart configuration", e);
+ }
+ return inputPorts;
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) {
+ Set<ActivityOutputPort> outputPorts = new HashSet<>();
+ try {
+ Query query = getQuery(configuration);
+ List<Attribute> attributes = query.getAttributes();
+ if (query.getFormatter() == null) {
+ // Create new output ports corresponding to attributes
+ for (Attribute attribute : attributes) {
+ String name = attribute.getQualifiedName();
+ ActivityOutputPort outputPort = null;
+ if (attribute.getAttributes() != null) {
+ outputPorts.add(edits.createActivityOutputPort(name, 2,
+ BiomartActivity.STREAM_RESULTS ? 1 : 2));
+ } else {
+ outputPorts.add(edits.createActivityOutputPort(name, 1,
+ BiomartActivity.STREAM_RESULTS ? 0 : 1));
+ }
+ }
+ } else if (attributes.size() > 0) {
+ // create one port using the dataset name
+ Attribute attribute = attributes.get(0);
+ String name = attribute.getContainingDataset().getName();
+ outputPorts.add(edits.createActivityOutputPort(name, 0, 0));
+ }
+ } catch (JDOMException | IOException e) {
+ logger.warn("Error caluculating output ports from BioMart configuration", e);
+ }
+ return outputPorts;
+ }
+
+ public void setEdits(Edits edits) {
+ this.edits = edits;
+ }
+
+ private Query getQuery(JsonNode configuration) throws JDOMException, IOException {
+ String martQueryText = configuration.get("martQuery").asText();
+ Document document = builder.build(new StringReader(martQueryText));
+ MartQuery martQuery = MartServiceXMLHandler.elementToMartQuery(document.getRootElement(),
+ null);
+ return martQuery.getQuery();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityHealthChecker.java b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityHealthChecker.java
new file mode 100644
index 0000000..8e48635
--- /dev/null
+++ b/taverna-biomart-activity/src/main/java/net/sf/taverna/t2/activities/biomart/BiomartActivityHealthChecker.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import net.sf.taverna.t2.visit.VisitReport;
+
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
+
+
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+public class BiomartActivityHealthChecker extends RemoteHealthChecker {
+
+ public boolean canVisit(Object subject) {
+ if (subject == null) {
+ return false;
+ }
+ if (subject instanceof BiomartActivity) {
+ return true;
+ }
+ if (subject instanceof DisabledActivity) {
+ return (((DisabledActivity) subject).getActivity() instanceof BiomartActivity);
+ }
+ return false;
+ }
+
+ public VisitReport visit(Object o, List<Object> ancestors) {
+ Element biomartQueryElement = null;
+ Activity activity = (Activity) o;
+ if (activity instanceof BiomartActivity) {
+ String martQueryText = ((BiomartActivity)activity).getConfiguration().get("martQuery").asText();
+ SAXBuilder builder = new SAXBuilder();
+ try {
+ Document document = builder.build(new StringReader(martQueryText));
+ biomartQueryElement = document.getRootElement();
+ } catch (JDOMException | IOException e) {
+ e.printStackTrace();
+ }
+ } else if (activity instanceof DisabledActivity) {
+ biomartQueryElement = (Element) ((DisabledActivity) activity).getActivityConfiguration();
+ }
+ MartQuery biomartQuery = MartServiceXMLHandler.elementToMartQuery(biomartQueryElement, null);
+ return contactEndpoint(activity, biomartQuery.getMartService().getLocation());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/taverna-biomart-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
new file mode 100644
index 0000000..19aae39
--- /dev/null
+++ b/taverna-biomart-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
@@ -0,0 +1 @@
+# net.sf.taverna.t2.activities.biomart.BiomartActivityHealthChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context-osgi.xml b/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context-osgi.xml
new file mode 100644
index 0000000..d8df086
--- /dev/null
+++ b/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context-osgi.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="biomartActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+
+ <service ref="biomartActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+
+ <reference id="edits" interface="net.sf.taverna.t2.workflowmodel.Edits" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context.xml b/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context.xml
new file mode 100644
index 0000000..dcc0538
--- /dev/null
+++ b/taverna-biomart-activity/src/main/resources/META-INF/spring/biomart-activity-context.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="biomartActivityHealthChecker" class="net.sf.taverna.t2.activities.biomart.BiomartActivityHealthChecker" />
+
+ <bean id="biomartActivityFactory" class="net.sf.taverna.t2.activities.biomart.BiomartActivityFactory">
+ <property name="edits" ref="edits" />
+ </bean>
+
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/main/resources/schema.json
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/main/resources/schema.json b/taverna-biomart-activity/src/main/resources/schema.json
new file mode 100644
index 0000000..99eb9f2
--- /dev/null
+++ b/taverna-biomart-activity/src/main/resources/schema.json
@@ -0,0 +1,19 @@
+{
+ "$schema": "http://json-schema.org/draft-03/schema#",
+ "id": "http://ns.taverna.org.uk/2010/activity/biomart.schema.json",
+ "title": "Biomart activity configuration",
+ "type": "object",
+ "properties": {
+ "@context": {
+ "description": "JSON-LD context for interpreting the configuration as RDF",
+ "required": true,
+ "enum": ["http://ns.taverna.org.uk/2010/activity/biomart.context.json"]
+ },
+ "martQuery": {
+ "title": "Mart Query",
+ "description": "Biomart query in XML",
+ "type": "string",
+ "required": true,
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/test/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/test/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactoryTest.java b/taverna-biomart-activity/src/test/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactoryTest.java
new file mode 100644
index 0000000..78ed2f6
--- /dev/null
+++ b/taverna-biomart-activity/src/test/java/net/sf/taverna/t2/activities/biomart/BiomartActivityFactoryTest.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * @author David Withers
+ */
+public class BiomartActivityFactoryTest {
+
+ private BiomartActivityFactory factory;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ factory = new BiomartActivityFactory();
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.biomart.BiomartActivityFactory#createActivity()}.
+ */
+ @Test
+ public void testCreateActivity() {
+ BiomartActivity createActivity = factory.createActivity();
+ assertNotNull(createActivity);
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.biomart.BiomartActivityFactory#getActivityType()}.
+ */
+ @Test
+ public void testGetActivityURI() {
+ assertEquals(URI.create(BiomartActivity.URI), factory.getActivityType());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/src/test/resources/biomart-query.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/src/test/resources/biomart-query.xml b/taverna-biomart-activity/src/test/resources/biomart-query.xml
new file mode 100644
index 0000000..e0b43bd
--- /dev/null
+++ b/taverna-biomart-activity/src/test/resources/biomart-query.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MartQuery xmlns:biomart="http://org.embl.ebi.escience/xscufl-biomart/0.1alpha">
+ <MartService location="http://www.biomart.org/biomart/martservice" />
+ <MartDataset displayName="Homo sapiens genes (NCBI36)" name="hsapiens_gene_ensembl" type="TableSet" initialBatchSize="100" maximumBatchSize="50000" visible="false">
+ <MartURLLocation default="1" displayName="ENSEMBL 41 (SANGER)" host="www.biomart.org" name="ensembl" port="80" serverVirtualSchema="default" virtualSchema="default" visible="1" />
+ </MartDataset>
+ <Query virtualSchemaName="default" count="0" softwareVersion="0.5">
+ <Dataset name="hsapiens_gene_ensembl">
+ <Attribute name="chromosome_name" />
+ <Attribute name="go_description" />
+ <Filter name="chromosome_name" value="1" />
+ <Filter name="band_end" value="p36.32" />
+ <Filter name="band_start" value="p36.33" />
+ </Dataset>
+ </Query>
+</MartQuery>
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/pom.xml b/taverna-biomart-martservice/pom.xml
new file mode 100644
index 0000000..582a601
--- /dev/null
+++ b/taverna-biomart-martservice/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>org.biomart</groupId>
+ <artifactId>martservice</artifactId>
+ <packaging>bundle</packaging>
+ <name>MartService</name>
+ <version>2.0.1-SNAPSHOT</version>
+ <description>Biomart webservice API</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.7</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Private-Package>org.ensembl.mart.lib,org.ensembl.mart.lib.config,org.ensembl.mart.util</Private-Package>
+ <Import-Package>!org.ensembl.util,!org.ensembl.mart.editor,!oracle.sql,!gnu.getopt,!org.ewin.*,*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.biomart</groupId>
+ <artifactId>martj</artifactId>
+ <version>0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>com.springsource.org.jdom</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.httpclient</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.io</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ <repository>
+ <id>com.springsource.repository.bundles.release</id>
+ <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/release</url>
+ </repository>
+ <repository>
+ <id>com.springsource.repository.bundles.external</id>
+ <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/external</url>
+ </repository>
+ </repositories>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-biomart-martservice.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com:taverna/taverna-biomart-martservice.git</developerConnection>
+ <url>https://github.com/taverna/taverna-biomart-martservice/</url>
+ <tag>HEAD</tag>
+ </scm>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/DatasetLink.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/DatasetLink.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/DatasetLink.java
new file mode 100644
index 0000000..e5dccd4
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/DatasetLink.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: DatasetLink.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:55 $
+ * by $Author: davidwithers $
+ * Created on 12-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * The link between two MartDatasets and the list of possible the link IDs that
+ * could join the source and target MartDataset.
+ *
+ * @author David Withers
+ */
+public class DatasetLink {
+ private static final Comparator<DatasetLink> displayComparator = new DatasetLinkComparator();
+
+ private MartDataset sourceDataset;
+
+ private MartDataset targetDataset;
+
+ private Set<String> links = new HashSet<String>();
+
+ /**
+ * Constructs an instance of an <code>DatasetLink</code> with the
+ * specified source and target.
+ *
+ * @param sourceDataset
+ * the link source
+ * @param targetDataset
+ * the link target
+ */
+ public DatasetLink(MartDataset sourceDataset, MartDataset targetDataset) {
+ this.sourceDataset = sourceDataset;
+ this.targetDataset = targetDataset;
+ }
+
+ /**
+ * Returns the source Dataset.
+ *
+ * @return the source Dataset
+ */
+ public MartDataset getSourceDataset() {
+ return sourceDataset;
+ }
+
+ /**
+ * Sets the source Dataset.
+ *
+ * @param sourceDataset
+ * the sourceDataset to set
+ */
+ public void setSourceDataset(MartDataset sourceDataset) {
+ this.sourceDataset = sourceDataset;
+ }
+
+ /**
+ * Returns the target Dataset.
+ *
+ * @return the target Dataset
+ */
+ public MartDataset getTargetDataset() {
+ return targetDataset;
+ }
+
+ /**
+ * Sets the target Dataset.
+ *
+ * @param targetDataset
+ * the target Dataset to set
+ */
+ public void setTargetDataset(MartDataset targetDataset) {
+ this.targetDataset = targetDataset;
+ }
+
+ /**
+ * Returns the link IDs that could join the source and target MartDatasets.
+ *
+ * @return the link IDs that could join the source and target MartDatasets
+ */
+ public String[] getLinks() {
+ return links.toArray(new String[links.size()]);
+ }
+
+ /**
+ * Adds a link ID.
+ *
+ * @param link
+ * the link ID to add.
+ */
+ public void addLink(String link) {
+ links.add(link);
+ }
+
+ /**
+ * Returns true if this DatasetLink has link IDs.
+ *
+ * @return true if this DatasetLink has link IDs
+ */
+ public boolean hasLinks() {
+ return !links.isEmpty();
+ }
+
+ public String toString() {
+ return "[" + sourceDataset.getMartURLLocation().getDisplayName() + "] "
+ + sourceDataset.getDisplayName();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((sourceDataset == null) ? 0 : sourceDataset.hashCode());
+ result = PRIME * result + ((targetDataset == null) ? 0 : targetDataset.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final DatasetLink other = (DatasetLink) obj;
+ if (sourceDataset == null) {
+ if (other.sourceDataset != null)
+ return false;
+ } else if (!sourceDataset.equals(other.sourceDataset))
+ return false;
+ if (targetDataset == null) {
+ if (other.targetDataset != null)
+ return false;
+ } else if (!targetDataset.equals(other.targetDataset))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns a Comparator that compares DatasetLinks based on the display name
+ * of the source dataset and the display name of the MartURLLocation
+ * containing the source dataset.
+ *
+ * @return the display comparator
+ */
+ public static Comparator<DatasetLink> getDisplayComparator() {
+ return displayComparator;
+ }
+
+}
+
+/**
+ * Comparator that compares DatasetLinks based on the display name of the source
+ * MartDataset and the display name of the MartURLLocation containing the source
+ * MartDataset.
+ *
+ * @author David Withers
+ */
+class DatasetLinkComparator implements Comparator<DatasetLink> {
+
+ /**
+ * Compares two DatasetLinks based on the display name of the source dataset
+ * and the display name of the MartURLLocation containing the source
+ * dataset.
+ *
+ * @param o1
+ * the first DatasetLink to be compared
+ * @param o2
+ * the second DatasetLink to be compared
+ * @return a negative integer, zero, or a positive integer as the first
+ * argument is less than, equal to, or greater than the second
+ */
+ public int compare(DatasetLink o1, DatasetLink o2) {
+ MartDataset ds1 = o1.getSourceDataset();
+ MartDataset ds2 = o2.getSourceDataset();
+ int result = ds1.getDisplayName().compareTo(ds2.getDisplayName());
+ if (result == 0) {
+ result = ds1.getMartURLLocation().getDisplayName().compareTo(
+ ds2.getMartURLLocation().getDisplayName());
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartDataset.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartDataset.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartDataset.java
new file mode 100644
index 0000000..8c0f584
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartDataset.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartDataset.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/04 14:17:19 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.util.Comparator;
+
+/**
+ * The dataset returned by a BioMart web service.
+ *
+ * @author David Withers
+ */
+public class MartDataset {
+ private static final Comparator<MartDataset> displayComparator = new MartDatasetComparator();
+
+ private String type;
+
+ private String name;
+
+ private String displayName;
+
+ private boolean visible;
+
+ private long initialBatchSize;
+
+ private long maximumBatchSize;
+
+ private String interfaceValue;
+
+ private String modified;
+
+ private MartURLLocation martURLLocation;
+
+ /**
+ * Returns the displayName.
+ *
+ * @return the displayName.
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /**
+ * Sets the displayName.
+ *
+ * @param displayName
+ * the displayName to set.
+ */
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ /**
+ * Returns the initialBatchSize.
+ *
+ * @return the initialBatchSize.
+ */
+ public long getInitialBatchSize() {
+ return initialBatchSize;
+ }
+
+ /**
+ * Sets the initialBatchSize.
+ *
+ * @param initialBatchSize
+ * the initialBatchSize to set.
+ */
+ public void setInitialBatchSize(long initialBatchSize) {
+ this.initialBatchSize = initialBatchSize;
+ }
+
+ /**
+ * Returns the maximumBatchSize.
+ *
+ * @return the maximumBatchSize.
+ */
+ public long getMaximumBatchSize() {
+ return maximumBatchSize;
+ }
+
+ /**
+ * Sets the maximumBatchSize.
+ *
+ * @param maximumBatchSize
+ * the maximumBatchSize to set.
+ */
+ public void setMaximumBatchSize(long maximumBatchSize) {
+ this.maximumBatchSize = maximumBatchSize;
+ }
+
+ /**
+ * Returns the name.
+ *
+ * @return the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name
+ * the name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the type.
+ *
+ * @return the type.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Sets the type.
+ *
+ * @param type
+ * the type to set.
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns the visible flag.
+ *
+ * @return the visible flag
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /**
+ * Sets the visible flag.
+ *
+ * @param visible
+ * the visible flag
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
+
+ /**
+ * Returns the modified date.
+ *
+ * @return the modified date
+ */
+ public String getModified() {
+ return modified;
+ }
+
+ /**
+ * Sets the modified date.
+ *
+ * @param modified the new modified date
+ */
+ public void setModified(String modified) {
+ this.modified = modified;
+ }
+
+ /**
+ * Returns the interface.
+ *
+ * @return the interface
+ */
+ public String getInterface() {
+ return interfaceValue;
+ }
+
+ /**
+ * Sets the interface.
+ *
+ * @param interfaceValue the new interface
+ */
+ public void setInterface(String interfaceValue) {
+ this.interfaceValue = interfaceValue;
+ }
+
+ /**
+ * Returns the martURLLocation.
+ *
+ * @return the martURLLocation
+ */
+ public MartURLLocation getMartURLLocation() {
+ return martURLLocation;
+ }
+
+ /**
+ * Sets the martURLLocation.
+ *
+ * @param martURLLocation
+ * the martURLLocation to set.
+ */
+ public void setMartURLLocation(MartURLLocation martURLLocation) {
+ this.martURLLocation = martURLLocation;
+ }
+
+ /**
+ * Returns the virtualSchema of the martURLLocation. If the martURLLocation
+ * is null, null is returned.
+ *
+ * @return the virtualSchema of the martURLLocation
+ */
+ public String getVirtualSchema() {
+ MartURLLocation martURLLocation = getMartURLLocation();
+ if (martURLLocation != null) {
+ return martURLLocation.getVirtualSchema();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the qualified name of this dataset in the format
+ * 'virtualSchemaName.datasetName'. If there is no virtualSchema the
+ * datasetName is returned.
+ *
+ * @return the qualified name of this dataset
+ */
+ public String getQualifiedName() {
+ String schema = getVirtualSchema();
+ if (schema != null) {
+ return schema + "." + getName();
+ } else {
+ return getName();
+ }
+ }
+
+ /**
+ * Returns the display name.
+ *
+ * @return the display name
+ */
+ public String toString() {
+ return getDisplayName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME
+ * result
+ + ((getQualifiedName() == null) ? 0 : getQualifiedName()
+ .hashCode());
+ return result;
+ }
+
+ /**
+ * Tests equality based on the qualified name.
+ *
+ * @return true if the objects are equal based on the qualified name
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final MartDataset other = (MartDataset) obj;
+ if (getQualifiedName() == null) {
+ if (other.getQualifiedName() != null)
+ return false;
+ } else if (!getQualifiedName().equals(other.getQualifiedName()))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns a Comparator that compares MartDatasets based on their display
+ * names.
+ *
+ * @return the display comparator
+ */
+ public static Comparator<MartDataset> getDisplayComparator() {
+ return displayComparator;
+ }
+
+}
+
+/**
+ * Comparator that compares MartDatasets based on their display names.
+ *
+ * @author David Withers
+ */
+class MartDatasetComparator implements Comparator<MartDataset> {
+
+ /**
+ * Compares two MartDatasets based on their display names.
+ *
+ * @param martDataset1
+ * the first MartDataset to be compared
+ * @param martDataset2
+ * the second MartDataset to be compared
+ * @return a negative integer, zero, or a positive integer as the first
+ * argument is less than, equal to, or greater than the second
+ */
+ public int compare(MartDataset martDataset1, MartDataset martDataset2) {
+ return martDataset1.getDisplayName().compareTo(martDataset2.getDisplayName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartQuery.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartQuery.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartQuery.java
new file mode 100644
index 0000000..9f75566
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartQuery.java
@@ -0,0 +1,436 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartQuery.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:55 $
+ * by $Author: davidwithers $
+ * Created on 08-May-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Dataset;
+import org.biomart.martservice.query.Filter;
+import org.biomart.martservice.query.Link;
+import org.biomart.martservice.query.Query;
+import org.ensembl.mart.lib.config.AttributeDescription;
+import org.ensembl.mart.lib.config.DatasetConfig;
+
+/**
+ * Class for creating queries to send to a BioMart web service.
+ *
+ * @author David Withers
+ */
+public class MartQuery {
+ private MartService martService;
+
+ private MartDataset martDataset;
+
+ private Query query;
+
+ private Map<String, String> linkedDatasets = new HashMap<String, String>();
+
+ private String softwareVersion;
+
+ public MartQuery() {
+
+ }
+
+ public MartQuery(MartService martService, MartDataset martDataset, String requestId) {
+ String version = null;
+ try {
+ version = martService.getVersion(martDataset.getMartURLLocation());
+ } catch (MartServiceException e) {
+ //assume it's a pre 0.5 mart service
+ }
+ setMartService(martService);
+ setMartDataset(martDataset);
+ if (version == null || version.equals("0.4")) {
+ setQuery(new Query(martDataset.getVirtualSchema(), null, requestId));
+ } else {
+ setQuery(new Query(martDataset.getVirtualSchema(), version, requestId));
+ }
+ }
+
+ /**
+ * @param martService
+ * @param martDataset
+ * @param query
+ */
+ public MartQuery(MartService martService, MartDataset martDataset,
+ Query query) {
+ setMartService(martService);
+ setMartDataset(martDataset);
+ setQuery(query);
+ }
+
+ /**
+ * Returns the martDataset.
+ *
+ * @return the martDataset.
+ */
+ public MartDataset getMartDataset() {
+ return martDataset;
+ }
+
+ /**
+ * Sets the martDataset.
+ *
+ * @param martDataset
+ * the martDataset to set.
+ */
+ public void setMartDataset(MartDataset martDataset) {
+ this.martDataset = martDataset;
+ }
+
+ /**
+ * Returns the martService.
+ *
+ * @return the martService.
+ */
+ public MartService getMartService() {
+ return martService;
+ }
+
+ /**
+ * Sets the martService.
+ *
+ * @param martService
+ * the martService to set.
+ */
+ public void setMartService(MartService martService) {
+ this.martService = martService;
+ }
+
+ /**
+ * Returns the query.
+ *
+ * @return the query.
+ */
+ public Query getQuery() {
+ return query;
+ }
+
+ /**
+ * Sets the query.
+ *
+ * @param query
+ * the query to set.
+ */
+ public void setQuery(Query query) {
+ this.query = query;
+ softwareVersion = query.getSoftwareVersion();
+ }
+
+ /**
+ * Adds the ID that links the specified dataset to the initial dataset.
+ *
+ * @param datasetName
+ * the dataset
+ * @param linkId
+ * the link ID
+ */
+ public void addLinkedDataset(String datasetName, String linkId) {
+ linkedDatasets.put(datasetName, linkId);
+ }
+
+ /**
+ * Removes a dataset and any datasets linked to it.
+ *
+ * @param datasetName
+ * the dataset to remove
+ */
+ public void removeLinkedDataset(String datasetName) {
+ linkedDatasets.remove(datasetName);
+ if (query.containsDataset(datasetName)) {
+ Dataset dataset = query.getDataset(datasetName);
+ dataset.removeAllAttributes();
+ dataset.removeAllFilters();
+ query.removeDataset(dataset);
+ for (Link link : query.getLinks(datasetName)) {
+ removeLinkedDataset(link.getTarget());
+ }
+
+ }
+ if (query.containsLink(datasetName)) {
+ query.removeLink(query.getLink(datasetName));
+ }
+ }
+
+ /**
+ * Changes the ID that links a dataset. This method performs no function,
+ * nor does it throw an exception, if the specified dataset does not exist.
+ *
+ * @param datasetName
+ * the dataset
+ * @param linkId
+ * the link ID
+ */
+ public void changeLinkedDataset(String datasetName, String linkId) {
+ if (linkedDatasets.containsKey(datasetName)) {
+ linkedDatasets.put(datasetName, linkId);
+ if (query.containsLink(datasetName)) {
+ query.getLink(datasetName).setDefaultLink(linkId);
+ }
+ }
+ }
+
+ public Set<String> getLinkedDatasets() {
+ return linkedDatasets.keySet();
+ }
+
+ public String getLink(String datasetName) {
+ return (String) linkedDatasets.get(datasetName);
+ }
+
+ /**
+ * Returns the Datasets that this Query contains in the order specified by
+ * the links.
+ *
+ * @return the Datasets that this Query contains in the order specified by
+ * the links
+ */
+ public List<Dataset> getDatasetsInLinkOrder() {
+ if (query.getLinks().size() > 0) {
+ List<Dataset> datasets = new ArrayList<Dataset>();
+ datasets.addAll(getLinkedDatasets(martDataset.getName()));
+ // add other datasets
+ for (Dataset dataset : query.getDatasets()) {
+ if (!datasets.contains(dataset)) {
+ datasets.add(dataset);
+ }
+ }
+ return datasets;
+ } else {
+ return query.getDatasets();
+ }
+ }
+
+ /**
+ * @param dataset
+ * @return
+ */
+ private List<Dataset> getLinkedDatasets(String dataset) {
+ List<Dataset> datasets = new ArrayList<Dataset>();
+ datasets.add(query.getDataset(dataset));
+ if (query.containsLink(dataset)) {
+ Link link = query.getLink(dataset);
+ if (!link.getTarget().equals(martDataset.getName())) {
+ datasets.addAll(getLinkedDatasets(link.getTarget()));
+ }
+ }
+ return datasets;
+ }
+
+ /**
+ * Returns all the Attributes from all the Datasets in this Query in the
+ * order specified by the links.
+ *
+ * @return all the Attributes from all the Datasets in this Query in the
+ * order specified by the links
+ */
+ public List<Attribute> getAttributesInLinkOrder() {
+ List<Attribute> attributes = new ArrayList<Attribute>();
+ List<Dataset> datasets;
+ if (softwareVersion == null) {
+ datasets = getDatasetsInLinkOrder();
+ } else {
+ datasets = query.getDatasets();
+ }
+ for (Dataset dataset : datasets) {
+ attributes.addAll(dataset.getAttributes());
+ }
+ return attributes;
+ }
+
+ /**
+ * Adds an Attribute to the Dataset with the given datasetName. If the Query
+ * has no Dataset with the given datasetName then a new Dataset is created.
+ *
+ * @param datasetName
+ * the name of the Dataset to add the Attribute to
+ * @param attribute
+ * the Attribute to add
+ * @throws MartServiceException
+ */
+ public void addAttribute(String datasetName, Attribute attribute) {
+ if (!query.containsDataset(datasetName)) {
+ Dataset dataset = new Dataset(datasetName);
+ if (datasetName.equals(martDataset.getName())) {
+ query.addDataset(0, dataset);
+ } else {
+ query.addDataset(dataset);
+ }
+ }
+ Dataset dataset = query.getDataset(datasetName);
+ dataset.addAttribute(attribute);
+ }
+
+ /**
+ * Removes an Attribute from its containing Dataset.
+ *
+ * @param attribute
+ */
+ public void removeAttribute(Attribute attribute) {
+ Dataset dataset = attribute.getContainingDataset();
+ if (dataset != null) {
+ if (dataset.removeAttribute(attribute)) {
+ if (!dataset.hasAttributes() && !dataset.hasFilters()) {
+ Query query = dataset.getContainingQuery();
+ if (query != null) {
+ query.removeDataset(dataset);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds a Filter to the Dataset with the given datasetName. If the Query has
+ * no Dataset with the given datasetName then a new Dataset is created.
+ *
+ * @param datasetName
+ * the name of the Dataset to add the Filter to
+ * @param filter
+ * the Filter to add
+ * @throws MartServiceException
+ */
+ public void addFilter(String datasetName, Filter filter) {
+ if (!query.containsDataset(datasetName)) {
+ Dataset dataset = new Dataset(datasetName);
+ if (datasetName.equals(martDataset.getName())) {
+ query.addDataset(0, dataset);
+ } else {
+ query.addDataset(dataset);
+ }
+ }
+ Dataset dataset = query.getDataset(datasetName);
+ dataset.addFilter(filter);
+ }
+
+ /**
+ * Removes a Filter from its containing Dataset.
+ *
+ * @param filter
+ */
+ public void removeFilter(Filter filter) {
+ Dataset dataset = filter.getContainingDataset();
+ if (dataset != null) {
+ if (dataset.removeFilter(filter)) {
+ if (!dataset.hasAttributes() && !dataset.hasFilters()) {
+ Query query = dataset.getContainingQuery();
+ if (query != null) {
+ query.removeDataset(dataset);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @throws MartServiceException
+ */
+ public void calculateLinks() throws MartServiceException {
+ if (softwareVersion == null) {
+ if (!martService.linksCalculated()) {
+ martService.calculateLinks();
+ }
+ for (Link link : query.getLinks()) {
+ query.removeLink(link);
+ }
+ for (Dataset dataset : query.getDatasets()) {
+ if (!martDataset.getName().equals(dataset.getName())) {
+ addLinks(dataset.getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * @param source
+ * @throws MartServiceException
+ */
+ public void addLinks(String source) throws MartServiceException {
+ MartDataset sourceDataset = martService.getDataset(martDataset
+ .getVirtualSchema(), source);
+ MartDataset targetDataset = martDataset;
+ List<MartDataset> path = martService.getPath(sourceDataset, targetDataset);
+ if (path == null) {
+ path = martService.getPath(targetDataset, sourceDataset);
+ }
+ if (path == null) {
+ throw new MartServiceException("No link between " + source
+ + " and " + targetDataset.getName());
+ }
+ Iterator<MartDataset> iter = path.iterator();
+ if (iter.hasNext()) {
+ MartDataset lastDataset = (MartDataset) iter.next();
+ while (iter.hasNext()) {
+ MartDataset dataset = (MartDataset) iter.next();
+ DatasetLink link = martService.getLinkBetween(lastDataset,
+ dataset);
+ String linkId = link.getLinks()[0];
+ if (link.getLinks().length > 1) {
+ if (getLink(source) != null) {
+ linkId = getLink(source);
+ } else {
+ List<Attribute> attributes = query.getDataset(source)
+ .getAttributes();
+ if (attributes.size() > 0) {
+ Attribute attribute = (Attribute) attributes.get(0);
+ DatasetConfig config = martService
+ .getDatasetConfig(sourceDataset);
+ if (config.containsAttributeDescription(attribute
+ .getName())) {
+ AttributeDescription description = config
+ .getAttributeDescriptionByInternalName(attribute
+ .getName());
+ String datasetLink = description
+ .getDatasetLink();
+ if (datasetLink != null) {
+ linkId = datasetLink;
+ }
+ }
+ }
+ }
+ }
+ query.addLink(new Link(lastDataset.getName(),
+ dataset.getName(), linkId));
+ lastDataset = dataset;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartRegistry.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartRegistry.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartRegistry.java
new file mode 100644
index 0000000..93bf04d
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartRegistry.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartRegistry.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:55 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The MartRegistry returned by a BioMart web service.
+ *
+ * @author David Withers
+ */
+public class MartRegistry {
+ private List<MartURLLocation> martURLLocations = new ArrayList<MartURLLocation>();
+
+ /**
+ * Returns the martURLLocations.
+ *
+ * @return the martURLLocations.
+ */
+ public MartURLLocation[] getMartURLLocations() {
+ return martURLLocations
+ .toArray(new MartURLLocation[martURLLocations.size()]);
+ }
+
+ /**
+ * Adds a martURLLocation to the registry.
+ *
+ * @param martURLLocations
+ * the martURLLocations to add.
+ */
+ public void addMartURLLocation(MartURLLocation martURLLocation) {
+ martURLLocations.add(martURLLocation);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((martURLLocations == null) ? 0 : martURLLocations.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final MartRegistry other = (MartRegistry) obj;
+ if (martURLLocations == null) {
+ if (other.martURLLocations != null)
+ return false;
+ } else if (!martURLLocations.equals(other.martURLLocations))
+ return false;
+ return true;
+ }
+
+}
[06/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/BiomobyObjectTree.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/BiomobyObjectTree.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/BiomobyObjectTree.java
new file mode 100644
index 0000000..7ca2578
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/BiomobyObjectTree.java
@@ -0,0 +1,635 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.swing.ImageIcon;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.JTextField;
+import javax.swing.JTree;
+import javax.swing.ToolTipManager;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyPanel;
+import net.sf.taverna.t2.activities.biomoby.datatypedescriptions.BiomobyDatatypeDescription;
+import net.sf.taverna.t2.activities.biomoby.edits.AddUpstreamObjectEdit;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyObjectActivityItem;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyQueryHelper;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workflowmodel.CompoundEdit;
+import net.sf.taverna.t2.workflowmodel.Dataflow;
+import net.sf.taverna.t2.workflowmodel.Edit;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.utils.Tools;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.MobyException;
+
+/**
+ * Creates a Datatype tree for any BioMOBY registry. The tree allows the user to
+ * add nodes to the workflow. Includes the ability to search for datatypes too.
+ *
+ * @author Eddie Kawas, The BioMoby Project
+ *
+ */
+public class BiomobyObjectTree {
+
+ private static Logger logger = Logger
+ .getLogger(BiomobyObjectTree.class);
+
+ private JTree tree;
+ private String registryEndpoint = "";
+ private String registryNamespace = "";
+ private static String SEARCH_DATATYPE_TEXT = "Type to search!";
+ private FilterTreeModel model;
+ private final EditManager editManager;
+ private final FileManager fileManager;
+
+ /**
+ * Default constructor. Creates a BiomobyObjectTree for the default Biomoby
+ * registry
+ */
+ public BiomobyObjectTree(EditManager editManager, FileManager fileManager) {
+ this(CentralImpl.DEFAULT_ENDPOINT, CentralImpl.DEFAULT_NAMESPACE, editManager, fileManager);
+ }
+
+ /**
+ *
+ * @param url
+ * the Biomoby registry endpoint URL to build a tree for
+ * @param uri
+ * the Biomoby registry namespace URI to build a tree for
+ */
+ public BiomobyObjectTree(String url, String uri, EditManager editManager, FileManager fileManager) {
+ this.registryEndpoint = url;
+ this.registryNamespace = uri;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ /*
+ * method that inserts our BiomobyDatatypeDescription object into our tree
+ */
+ private void insertDescriptionIntoTree(
+ BiomobyDatatypeDescription description,
+ HashMap<String, FilterTreeNode> nodeMap,
+ HashMap<String, BiomobyDatatypeDescription> descriptionMap) {
+ FilterTreeNode node = nodeMap.containsKey(description.getName()) ? nodeMap
+ .get(description.getName())
+ : new FilterTreeNode(description);
+
+ String parent = description.getParent();
+ if (parent.equals(""))
+ parent = "Object";
+ FilterTreeNode pNode = nodeMap.containsKey(parent) ? nodeMap
+ .get(parent) : new FilterTreeNode(descriptionMap.get(parent));
+ pNode.add(node);
+ nodeMap.put(description.getName(), node);
+ nodeMap.put(parent, pNode);
+ }
+
+ /**
+ *
+ * @return a Tree containing the datatype ontology for the specified biomoby
+ * registry
+ * @throws MobyException
+ * if there is a problem comunicating with the specified biomoby
+ * registry
+ */
+ public Component getDatatypeTree() throws MobyException {
+ BiomobyQueryHelper bqh = new BiomobyQueryHelper(getRegistryEndpoint(),
+ getRegistryNamespace());
+ List<BiomobyDatatypeDescription> descriptions = bqh
+ .findDatatypeDescriptions();
+
+ // create a tree from all of the nodes
+ HashMap<String, BiomobyDatatypeDescription> descriptionMap = new HashMap<String, BiomobyDatatypeDescription>();
+ HashMap<String, FilterTreeNode> nodeMap = new HashMap<String, FilterTreeNode>();
+ for (BiomobyDatatypeDescription d : descriptions) {
+ // PRECONDITION: datatype names are unique across the ontology
+ descriptionMap.put(d.getDatatypeName(), d);
+ }
+
+ nodeMap.put("Object", new FilterTreeNode(descriptionMap.get("Object")));
+ for (BiomobyDatatypeDescription d : descriptions) {
+ if (!d.getName().equals("Object"))
+ insertDescriptionIntoTree(d, nodeMap, descriptionMap);
+ }
+ // construct a new tree with our root node
+ tree = new JTree(nodeMap.get("Object"));
+
+ // only allow one node to be selected at once
+ tree.getSelectionModel().setSelectionMode(
+ TreeSelectionModel.SINGLE_TREE_SELECTION);
+ model = new FilterTreeModel((FilterTreeNode) tree.getModel().getRoot());
+ tree.setModel(model);
+
+ // set up the icon and tooltips for the nodes in the tree
+ ImageIcon icon = new ImageIcon(BiomobyObjectActivityItem.class
+ .getResource("/biomoby_object.png"));
+ if (icon != null) {
+ DefaultTreeCellRenderer renderer = new DatatypeTreeRenderer();
+ renderer.setLeafIcon(icon);
+ renderer.setOpenIcon(icon);
+ renderer.setClosedIcon(icon);
+ renderer.setIcon(icon);
+ tree.setCellRenderer(renderer);
+ }
+
+ // add a mouse listener to catch context clicks
+ // the listener adds the selected datatype to the workflow
+ // it also adds the datatype's container relationships
+ tree.addMouseListener(new BiomobyObjectTreeMouseListener());
+ // clear the hashmaps to clear some memory
+ nodeMap.clear();
+ descriptionMap.clear();
+ // register our tree for tool tips
+ ToolTipManager.sharedInstance().registerComponent(tree);
+ // insert the tree into a scrollpane
+ JScrollPane treeView = new JScrollPane(tree);
+ treeView.setSize(getFrameSize());
+
+ // create a new panel to hold the scrollpane and a search box
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.add(treeView, BorderLayout.CENTER);
+ JTextField search = new JTextField(SEARCH_DATATYPE_TEXT);
+ panel.add(search, BorderLayout.PAGE_END);
+ search.addKeyListener(new KeyListener() {
+ public void keyPressed(KeyEvent e) {
+ if (e.getSource() instanceof JTextField) {
+ JTextField field = (JTextField) e.getSource();
+ if (field.getText().trim().equals(
+ BiomobyObjectTree.SEARCH_DATATYPE_TEXT)) {
+ field.setText("");
+ }
+ }
+ }
+
+ public void keyReleased(KeyEvent e) {
+ if (e.getSource() instanceof JTextField) {
+ JTextField field = (JTextField) e.getSource();
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ field.setText(SEARCH_DATATYPE_TEXT);
+ model.setFilter(null);
+ return;
+ }
+ // filter our tree
+ if (!field.getText().trim().equals(
+ BiomobyObjectTree.SEARCH_DATATYPE_TEXT)) {
+ // does our filter tree model exist yet?
+ model.setFilter(field.getText().trim());
+ }
+ }
+ }
+
+ public void keyTyped(KeyEvent e) {
+
+ }
+ });
+ search.addFocusListener(new FocusListener() {
+
+ public void focusGained(FocusEvent e) {
+ if (e.getSource() instanceof JTextField) {
+ JTextField field = (JTextField) e.getSource();
+ if (field.getText().trim().equals(
+ BiomobyObjectTree.SEARCH_DATATYPE_TEXT)) {
+ field.setText("");
+ }
+ }
+ }
+
+ public void focusLost(FocusEvent e) {
+ if (e.getSource() instanceof JTextField) {
+ JTextField field = (JTextField) e.getSource();
+ if (field.getText().trim().equals("")) {
+ field.setText(SEARCH_DATATYPE_TEXT);
+ }
+ }
+ }
+ });
+ // done
+ panel.setToolTipText("Datatype Viewer for " + getRegistryEndpoint().toString());
+ return panel;
+ }
+
+ /**
+ *
+ * @param registryEndpoint
+ * the endpoint to set
+ */
+ public void setRegistryEndpoint(String registryEndpoint) {
+ this.registryEndpoint = registryEndpoint;
+ }
+
+ /**
+ *
+ * @param registryNamespace
+ * the namespace to set
+ */
+ public void setRegistryNamespace(String registryNamespace) {
+ this.registryNamespace = registryNamespace;
+ }
+
+ /**
+ *
+ * @return the registry endpoint that this tree is using
+ */
+ public String getRegistryEndpoint() {
+ return registryEndpoint;
+ }
+
+ /**
+ *
+ * @return the registry namespace that this tree is using
+ */
+ public String getRegistryNamespace() {
+ return registryNamespace;
+ }
+
+ /**
+ * returns the frame size as a dimension for the content pane housing this
+ * action
+ */
+ public Dimension getFrameSize() {
+ return new Dimension(550, 450);
+ }
+
+ /*
+ * A mouse listener for our datatype tree
+ */
+ private class BiomobyObjectTreeMouseListener implements MouseListener {
+ public void mouseClicked(MouseEvent me) {
+ }
+
+ public void mousePressed(MouseEvent me) {
+ mouseReleased(me);
+ }
+
+ public void mouseReleased(MouseEvent me) {
+ if (me.isPopupTrigger()) // right click, show popup menu
+ {
+ TreePath path = tree.getPathForLocation(me.getX(), me.getY());
+ if (path == null)
+ return;
+
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
+ .getLastSelectedPathComponent();
+ if (node == null)
+ return;
+
+ final String selectedObject = node.toString();
+ final BiomobyDatatypeDescription bdd = (BiomobyDatatypeDescription) node
+ .getUserObject();
+ final JPopupMenu menu = new JPopupMenu();
+ // Create and add a menu item for adding to the
+ // item to the workflow
+ JMenuItem item = new JMenuItem("Add Datatype - '"
+ + selectedObject + "' to the workflow?");
+
+ item.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent ae) {
+
+ try {
+ Dataflow dataflow = fileManager.getCurrentDataflow();
+ List<Edit<?>> compoundEdits = new ArrayList<Edit<?>>();
+ List<Edit<?>> editList = new ArrayList<Edit<?>>();
+
+ String name = Tools.uniqueProcessorName(
+ selectedObject, dataflow);
+
+ BiomobyObjectActivityConfigurationBean configBean = new BiomobyObjectActivityConfigurationBean();
+ configBean.setMobyEndpoint(bdd
+ .getActivityConfiguration()
+ .getMobyEndpoint());
+ configBean.setAuthorityName("");
+ configBean.setServiceName(selectedObject);
+
+ Edits edits = editManager.getEdits();
+ net.sf.taverna.t2.workflowmodel.Processor sourceProcessor = edits
+ .createProcessor(name);
+ BiomobyObjectActivity boActivity = new BiomobyObjectActivity();
+ Edit<?> configureActivityEdit = edits
+ .getConfigureActivityEdit(boActivity,
+ configBean);
+ editList.add(configureActivityEdit);
+
+ editList
+ .add(edits
+ .getDefaultDispatchStackEdit(sourceProcessor));
+
+ Edit<?> addActivityToProcessorEdit = edits
+ .getAddActivityEdit(sourceProcessor,
+ boActivity);
+ editList.add(addActivityToProcessorEdit);
+
+ editList.add(edits.getAddProcessorEdit(dataflow,
+ sourceProcessor));
+
+ CompoundEdit compoundEdit = new CompoundEdit(
+ editList);
+ compoundEdits.add(compoundEdit);
+ compoundEdit.doEdit();
+
+ // process relationships
+ Edit<?> edit = new AddUpstreamObjectEdit(dataflow,
+ sourceProcessor, boActivity, edits);
+ editManager.doDataflowEdit(dataflow, edit);
+
+ } catch (Exception e) {
+ logger.error("Could not add datatype", e);
+ }
+ }
+ });
+ item.setIcon(MobyPanel.getIcon("/Add24.gif"));
+
+ // add the components to the menus
+ menu.add(new JLabel("Add to workflow ... ", JLabel.CENTER));
+ menu.add(new JSeparator());
+ menu.add(item);
+ // show the window
+ menu.show(me.getComponent(), me.getX(), me.getY());
+ }
+ }
+
+ public void mouseEntered(MouseEvent me) {
+ }
+
+ public void mouseExited(MouseEvent me) {
+ }
+ }
+
+ private static class DatatypeTreeRenderer extends DefaultTreeCellRenderer {
+
+ private static final long serialVersionUID = 7287097980554656834L;
+
+ // the max tool tip length
+ private static int MAX_TOOLTIP_LENGTH = 300;
+
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree, Object value,
+ boolean sel, boolean expanded, boolean leaf, int row,
+ boolean hasFocus) {
+ if (value instanceof DefaultMutableTreeNode) {
+ if (((DefaultMutableTreeNode) value).getUserObject() instanceof BiomobyDatatypeDescription) {
+ BiomobyDatatypeDescription desc = (BiomobyDatatypeDescription) ((DefaultMutableTreeNode) value)
+ .getUserObject();
+ String d = desc.getDescription().trim();
+ // we only keep MAX_TOOLTIP_LENGTH characters of the string
+ if (d.length() > MAX_TOOLTIP_LENGTH)
+ d = d.substring(0, MAX_TOOLTIP_LENGTH) + "...";
+ setToolTipText("<html><body><div style='width:200px;'><span>"
+ + d + "</span></div></body></html>");
+
+ ToolTipManager.sharedInstance().setDismissDelay(
+ Integer.MAX_VALUE);
+ }
+ }
+ return super.getTreeCellRendererComponent(tree, value, sel,
+ expanded, leaf, row, hasFocus);
+ }
+ }
+
+ /*
+ * Shamelessly stolen from t2. Made the Filter a simple string filter and
+ * modified the code a bit to make it relevant to my tree
+ */
+ private final class FilterTreeModel extends DefaultTreeModel {
+
+ private static final long serialVersionUID = 8446366558654481274L;
+ String currentFilter;
+
+ /**
+ *
+ * @param node
+ * the node to apply filtering to
+ */
+ public FilterTreeModel(FilterTreeNode node) {
+ this(node, null);
+ }
+
+ /**
+ *
+ * @param node
+ * the node to apply filtering to
+ * @param filter
+ * the actual filter we will apply
+ */
+ public FilterTreeModel(FilterTreeNode node, String filter) {
+ super(node);
+ currentFilter = filter;
+ node.setFilter(filter);
+ }
+
+ /**
+ *
+ * @param filter
+ * the filter to set and apply to our node
+ */
+ public void setFilter(String filter) {
+ if (root != null) {
+ currentFilter = filter;
+ ((FilterTreeNode) root).setFilter(filter);
+ Object[] path = { root };
+ fireTreeStructureChanged(this, path, null, null);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * javax.swing.tree.DefaultTreeModel#getChildCount(java.lang.Object)
+ */
+ public int getChildCount(Object parent) {
+ if (parent instanceof FilterTreeNode) {
+ return (((FilterTreeNode) parent).getChildCount());
+ }
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.tree.DefaultTreeModel#getChild(java.lang.Object,
+ * int)
+ */
+ public Object getChild(Object parent, int index) {
+ if (parent instanceof FilterTreeNode) {
+ return (((FilterTreeNode) parent).getChildAt(index));
+ }
+ return null;
+ }
+
+ /**
+ * Getter
+ *
+ * @return the filter that we are currently using
+ */
+ public String getCurrentFilter() {
+ return currentFilter;
+ }
+ }
+
+ private class FilterTreeNode extends DefaultMutableTreeNode {
+
+ private static final long serialVersionUID = -5269485070471940445L;
+ private String filter;
+ private boolean passed = true;
+ private List<FilterTreeNode> filteredChildren = new ArrayList<FilterTreeNode>();
+
+ public FilterTreeNode(Object userObject) {
+ super(userObject);
+ }
+
+ public String getFilter() {
+ return filter;
+ }
+
+ public void setFilter(String filter) {
+ this.filter = filter == null ? "" : filter;
+ passed = false;
+ filteredChildren.clear();
+ if (filter == null) {
+ passed = true;
+ passFilterDown(null);
+ } else if (pass(this)) {
+ passed = true;
+ passFilterDown(filter);
+ } else {
+ passFilterDown(filter);
+ passed = filteredChildren.size() != 0;
+ }
+ }
+
+ private boolean pass(FilterTreeNode node) {
+ if (getFilter().trim().equals("")) {
+ return true;
+ }
+ return node.getUserObject().toString().toLowerCase().trim()
+ .contains(getFilter().toLowerCase().trim());
+ }
+
+ private void passFilterDown(String filter) {
+ int realChildCount = super.getChildCount();
+ for (int i = 0; i < realChildCount; i++) {
+ FilterTreeNode realChild = (FilterTreeNode) super.getChildAt(i);
+ realChild.setFilter(filter);
+ if (realChild.isPassed()) {
+ filteredChildren.add(realChild);
+ }
+ }
+ }
+
+ public void add(FilterTreeNode node) {
+ super.add(node);
+ node.setFilter(filter);
+ if (node.isPassed()) {
+ filteredChildren.add(node);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.tree.DefaultMutableTreeNode#remove(int)
+ */
+ public void remove(int childIndex) {
+ if (filter != null) {
+ // as child indexes might be inconsistent..
+ throw new IllegalStateException(
+ "Can't remove while the filter is active");
+ }
+ super.remove(childIndex);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.tree.DefaultMutableTreeNode#getChildCount()
+ */
+ public int getChildCount() {
+ if (filter == null) {
+ return super.getChildCount();
+ }
+ return (filteredChildren.size());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.swing.tree.DefaultMutableTreeNode#getChildAt(int)
+ */
+ public FilterTreeNode getChildAt(int index) {
+ if (filter == null) {
+ return (FilterTreeNode) super.getChildAt(index);
+ }
+ return filteredChildren.get(index);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean isPassed() {
+ return passed;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ // Create a frame
+ String title = "TeST";
+ JFrame frame = new JFrame(title);
+
+ // Create a component to add to the frame
+/* Component comp = new BiomobyObjectTree(CentralImpl.DEFAULT_ENDPOINT,
+ CentralImpl.DEFAULT_NAMESPACE).getDatatypeTree();*/
+
+ Component comp = new BiomobyObjectTree("http://cropwiki.irri.org/cgi-bin/MOBY-Central.pl",
+ CentralImpl.DEFAULT_NAMESPACE, null, null).getDatatypeTree();
+
+ // Add the component to the frame's content pane;
+ // by default, the content pane has a border layout
+ frame.getContentPane().add(comp, BorderLayout.CENTER);
+
+ // Show the frame
+ int width = 300;
+ int height = 300;
+ frame.setSize(width, height);
+ frame.setVisible(true);
+
+ // Set to exit on close
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/DatatypeMenuItem.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/DatatypeMenuItem.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/DatatypeMenuItem.java
new file mode 100644
index 0000000..c5a7468
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/ui/DatatypeMenuItem.java
@@ -0,0 +1,196 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+
+import net.sf.taverna.t2.activities.biomoby.actions.MobyPanel;
+import net.sf.taverna.t2.activities.biomoby.query.BiomobyObjectActivityItem;
+import net.sf.taverna.t2.workbench.MainWindow;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.helper.HelpEnabledDialog;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.MobyException;
+
+import com.sun.java.help.impl.SwingWorker;
+
+/**
+ * DatatypeMenuItem is a JMenuItem that onClick produces a biomoby datatype tree
+ * that workbench users can utilize to add datatypes to any workflow.
+ *
+ * @author Edward Kawas
+ *
+ */
+public class DatatypeMenuItem extends JMenuItem {
+
+ private static Logger logger = Logger.getLogger(DatatypeMenuItem.class);
+ private static final long serialVersionUID = -1010828167358361441L;
+
+ private String endpoint;
+ private String namespace;
+
+ private final EditManager editManager;
+ private final FileManager fileManager;
+
+ /**
+ * Default constructor; Creates a menu item for the default registry
+ */
+ public DatatypeMenuItem(EditManager editManager, FileManager fileManager) {
+ this(CentralImpl.DEFAULT_ENDPOINT, CentralImpl.DEFAULT_NAMESPACE, editManager, fileManager);
+ }
+
+ /**
+ * Create a Datatype menu item for a biomoby registry given a specific
+ * endpoint and namespace
+ *
+ * @param endpoint
+ * the registry endpoint
+ * @param namespace
+ * the registry namespace
+ */
+ public DatatypeMenuItem(String endpoint, String namespace, EditManager editManager, FileManager fileManager) {
+ this(endpoint, namespace, endpoint, editManager, fileManager);
+ }
+
+ /*
+ * A private constructor. Every constructor ends up here
+ */
+ private DatatypeMenuItem(String endpoint, String namespace, String label, EditManager editManager, FileManager fileManager) {
+ // set up some specifics
+ this.endpoint = endpoint;
+ this.namespace = namespace;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ // set up the name, label and icon for this menu item
+ setName(label);
+ setText(label);
+ setIcon(new ImageIcon(BiomobyObjectActivityItem.class
+ .getResource("/biomoby_object.png")));
+ // enable the item
+ setEnabled(true);
+ // create an action listener to catch clicks
+ addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() instanceof DatatypeMenuItem) {
+ final DatatypeMenuItem item = (DatatypeMenuItem) e
+ .getSource();
+ // create a swing worker that creates our tree
+ SwingWorker worker = new SwingWorker() {
+ @Override
+ public Object construct() {
+ // create a progress bar ...
+ JProgressBar bar = new JProgressBar();
+ bar.setIndeterminate(true);
+ bar.setString("Creating datatype tree ...");
+ bar.setStringPainted(true);
+ // a dialog frame hold the bar
+ String title = "Datatype Tree Builder";
+ JDialog frame = new HelpEnabledDialog(MainWindow.getMainWindow(), title, false, null);
+ JLabel label = new JLabel(
+ "Constructing tree for:\n\t"
+ + item.getEndpoint());
+ JPanel panel = new JPanel();
+ panel.add(bar);
+ // the panel that holds the label and bar
+ JPanel panel1 = new JPanel();
+ panel1.setLayout(new BorderLayout());
+ panel1.add(panel, BorderLayout.NORTH);
+ panel1.add(label, BorderLayout.CENTER);
+ panel1.setBorder(BorderFactory.createEmptyBorder(
+ 20, 20, 20, 20));
+ frame.setContentPane(panel1);
+ frame.setResizable(false);
+ frame.pack();
+ frame.setVisible(true);
+ // do our task
+ getTreeForRegistry(item.getEndpoint(), item
+ .getNamespace());
+ // hide the progress bar ...
+ frame.setVisible(false);
+ frame.removeAll();
+ frame = null;
+ return null;
+ }
+ };
+ worker.start();
+ }
+ }
+ });
+ }
+
+ /**
+ * Set the registry namespace
+ *
+ * @param namespace
+ * the registry namespace that this menu item will use
+ */
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * Set the registry endpoint
+ *
+ * @param endpoint
+ * the registry endpoint that this menu item will use
+ */
+ public void setEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ /**
+ * Get the registry endpoint
+ *
+ * @return the registry endpoint that this menu item is using
+ */
+ public String getEndpoint() {
+ return endpoint;
+ }
+
+ /**
+ * Get the registry namespace
+ *
+ * @return the registry namespace that this menu item is using
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /*
+ * Creates a tree for a given registry
+ */
+ private void getTreeForRegistry(String endpoint, String namespace) {
+ Frame f = MobyPanel.CreateFrame("Datatype Viewer for " + endpoint);
+ try {
+ Component c = new BiomobyObjectTree(endpoint, namespace, editManager, fileManager)
+ .getDatatypeTree();
+ f.add(c);
+ f.setPreferredSize(c.getPreferredSize());
+ f.setMinimumSize(c.getPreferredSize());
+ f.pack();
+ } catch (MobyException e) {
+ logger.error(
+ "Error encountered while constructing datatype viewer:\n",
+ e);
+ }
+ f.setVisible(true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualView.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualView.java
new file mode 100644
index 0000000..4911721
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualView.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.util.Map.Entry;
+
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.actions.BiomobyActivityConfigurationAction;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyParserAction;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyServiceDetailsAction;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+@SuppressWarnings("serial")
+public class BiomobyActivityContextualView extends
+ HTMLBasedActivityContextualView<BiomobyActivityConfigurationBean> {
+
+ private EditManager editManager;
+ private final FileManager fileManager;
+ private final ActivityIconManager activityIconManager;
+
+ @Override
+ public Action getConfigureAction(Frame owner) {
+ BiomobyActivity activity = (BiomobyActivity) getActivity();
+ if (activity.getMobyService() != null && activity.containsSecondaries()) {
+ return new BiomobyActivityConfigurationAction((BiomobyActivity) getActivity(), owner,
+ editManager, fileManager, activityIconManager);
+ } else {
+ return null;
+ }
+ }
+
+ public BiomobyActivityContextualView(Activity<?> activity, EditManager editManager,
+ FileManager fileManager, ActivityIconManager activityIconManager,
+ ColourManager colourManager) {
+ super(activity, colourManager);
+ this.editManager = editManager;
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ this.activityIconManager = activityIconManager;
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ String html = "<tr><td>Endpoint</td><td>" + getConfigBean().getMobyEndpoint()
+ + "</td></tr>";
+ html += "<tr><td>Authority</td><td>" + getConfigBean().getAuthorityName() + "</td></tr>";
+ html += "<tr><td>Service</td><td>" + getConfigBean().getServiceName() + "</td></tr>";
+ if (getConfigBean().getSecondaries().size() > 0) {
+ html += "<tr><th colspan='2' align='left'>Secondaries</th></tr>";
+ for (Entry<String, String> entry : getConfigBean().getSecondaries().entrySet()) {
+ html += "<tr><td>" + entry.getKey() + "</td><td>" + entry.getValue() + "</td></tr>";
+ }
+ }
+ return html;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Biomoby service";
+ }
+
+ /**
+ * Gets the component from the {@link HTMLBasedActivityContextualView} and adds buttons to it
+ * allowing Moby service details
+ */
+ @Override
+ public JComponent getMainFrame() {
+ final JComponent mainFrame = super.getMainFrame();
+ JPanel flowPanel = new JPanel(new FlowLayout());
+
+ BiomobyActivity activity = (BiomobyActivity) getActivity();
+
+ JButton button = new JButton(new MobyServiceDetailsAction(activity, null, editManager,
+ fileManager));
+ flowPanel.add(button);
+ if (activity.getMobyService() != null) {
+ JButton button2 = new JButton(new MobyParserAction(activity, null, editManager,
+ fileManager));
+ flowPanel.add(button2);
+ }
+ mainFrame.add(flowPanel, BorderLayout.SOUTH);
+ return mainFrame;
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 100;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualViewFactory.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualViewFactory.java
new file mode 100644
index 0000000..942e52c
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyActivityContextualViewFactory.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+public class BiomobyActivityContextualViewFactory implements ContextualViewFactory<BiomobyActivity> {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+ private ColourManager colourManager;
+
+ public boolean canHandle(Object activity) {
+ return activity instanceof BiomobyActivity;
+ }
+
+ public List<ContextualView> getViews(BiomobyActivity activity) {
+ return Arrays.asList(new ContextualView[] { new BiomobyActivityContextualView(activity,
+ editManager, fileManager, activityIconManager, colourManager) });
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyConfigView.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyConfigView.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyConfigView.java
new file mode 100644
index 0000000..0e08e0b
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyConfigView.java
@@ -0,0 +1,108 @@
+/**
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.awt.BorderLayout;
+import java.util.Map;
+
+import javax.swing.JComponent;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationPanel;
+
+import org.apache.log4j.Logger;
+import org.biomoby.service.dashboard.data.ParametersTable;
+
+/**
+ * @author alanrw
+ *
+ */
+public class BiomobyConfigView extends ActivityConfigurationPanel<BiomobyActivity, BiomobyActivityConfigurationBean> {
+
+ private BiomobyActivity activity;
+ private BiomobyActivityConfigurationBean configuration;
+ private boolean changed = false;
+
+ private static Logger logger = Logger
+ .getLogger(BiomobyConfigView.class);
+ private ParametersTable parameterTable;
+
+ public BiomobyConfigView(BiomobyActivity activity) {
+ this.activity = activity;
+ initialise();
+ }
+
+ private void initialise() {
+ configuration = activity.getConfiguration();
+ this.setLayout(new BorderLayout());
+ parameterTable = activity.getParameterTable();
+ JComponent component = parameterTable.scrollable();
+ this.add(component, BorderLayout.NORTH);
+ validate();
+ }
+
+ /* (non-Javadoc)
+ * @see net.sf.taverna.t2.workbench.ui.views.contextualviews.ActivityConfigurationPanel#getConfiguration()
+ */
+ @Override
+ public BiomobyActivityConfigurationBean getConfiguration() {
+ return configuration;
+ }
+
+ /* (non-Javadoc)
+ * @see net.sf.taverna.t2.workbench.ui.views.contextualviews.ActivityConfigurationPanel#isConfigurationChanged()
+ */
+ @Override
+ public boolean isConfigurationChanged() {
+ Map<String,String> secondaries = configuration.getSecondaries();
+ int rows = parameterTable.getModel().getRowCount();
+ for (int i = 0; i < rows; i++) {
+ String key = (String)parameterTable.getModel().getValueAt(i,0);
+ String newValue = parameterTable.getModel().getValueAt(i,1).toString();
+ String currentValue = secondaries.get(key);
+ if (!currentValue.equals(newValue)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see net.sf.taverna.t2.workbench.ui.views.contextualviews.ActivityConfigurationPanel#noteConfiguration()
+ */
+ @Override
+ public void noteConfiguration() {
+ BiomobyActivityConfigurationBean newConfiguration =
+ (BiomobyActivityConfigurationBean) cloneBean(configuration);
+ Map<String,String> secondaries = newConfiguration.getSecondaries();
+ int rows = parameterTable.getModel().getRowCount();
+ for (int i = 0; i < rows; i++) {
+ String key = (String)parameterTable.getModel().getValueAt(i,0);
+ String value = parameterTable.getModel().getValueAt(i,1).toString();
+ secondaries.put(key, value);
+ }
+// logger.info(convertBeanToString(configuration));
+// logger.info("COnfiguration was " + configuration.hashCode());
+// logger.info(convertBeanToString(newConfiguration));
+// logger.info("New configuration is " + newConfiguration.hashCode());
+ configuration = newConfiguration;
+ }
+
+ @Override
+ public void refreshConfiguration() {
+ logger.info(convertBeanToString(activity.getConfiguration()));
+ removeAll();
+ initialise();
+ }
+
+ @Override
+ public boolean checkValues() {
+ // TODO Not yet implemented
+ return true;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualView.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualView.java
new file mode 100644
index 0000000..4ceed9b
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualView.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivityConfigurationBean;
+import net.sf.taverna.t2.activities.biomoby.actions.MobyObjectDetailsAction;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+@SuppressWarnings("serial")
+public class BiomobyObjectActivityContextualView extends
+ HTMLBasedActivityContextualView<BiomobyObjectActivityConfigurationBean> {
+
+ private EditManager editManager;
+ private final FileManager fileManager;
+
+ public BiomobyObjectActivityContextualView(Activity<?> activity, EditManager editManager,
+ FileManager fileManager, ColourManager colourManager) {
+ super(activity, colourManager);
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ String html = "<tr><td>Endpoint</td><td>" + getConfigBean().getMobyEndpoint()
+ + "</td></tr>";
+ html += "<tr><td>Authority</td><td>" + getConfigBean().getAuthorityName() + "</td></tr>";
+ html += "<tr><td>Datatype</td><td>" + getConfigBean().getServiceName() + "</td></tr>";
+ return html;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Biomoby Object service";
+ }
+
+ /**
+ * Gets the component from the {@link HTMLBasedActivityContextualView} and adds buttons to it
+ * allowing Moby object details
+ */
+ @Override
+ public JComponent getMainFrame() {
+ final JComponent mainFrame = super.getMainFrame();
+ BiomobyObjectActivity activity = (BiomobyObjectActivity) getActivity();
+ if (activity.getMobyObject() != null) {
+ JPanel flowPanel = new JPanel(new FlowLayout());
+ JButton button = new JButton(new MobyObjectDetailsAction(activity, null, editManager,
+ fileManager));
+ flowPanel.add(button);
+ mainFrame.add(flowPanel, BorderLayout.SOUTH);
+ }
+ return mainFrame;
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 100;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualViewFactory.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualViewFactory.java
new file mode 100644
index 0000000..0e6ea55
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyObjectActivityContextualViewFactory.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyObjectActivity;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class BiomobyObjectActivityContextualViewFactory implements
+ ContextualViewFactory<BiomobyObjectActivity> {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ColourManager colourManager;
+
+ public boolean canHandle(Object activity) {
+ return activity instanceof BiomobyObjectActivity;
+ }
+
+ public List<ContextualView> getViews(BiomobyObjectActivity activity) {
+ return Arrays.asList(new ContextualView[] { new BiomobyObjectActivityContextualView(
+ activity, editManager, fileManager, colourManager) });
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualView.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualView.java
new file mode 100644
index 0000000..91d4cd6
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualView.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivityConfigurationBean;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+@SuppressWarnings("serial")
+public class MobyParseDatatypeContextualView extends
+ HTMLBasedActivityContextualView<MobyParseDatatypeActivityConfigurationBean> {
+
+ public MobyParseDatatypeContextualView(Activity<?> activity, ColourManager colourManager) {
+ super(activity, colourManager);
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ String html = "<tr><td>Article name used by service</td><td>"
+ + getConfigBean().getArticleNameUsedByService() + "</td></tr>";
+ html += "<tr><td>Datatype</td><td>" + getConfigBean().getDatatypeName() + "</td></tr>";
+ html += "<tr><td>Registry endpoint</td><td>" + getConfigBean().getRegistryEndpoint()
+ + "</td></tr>";
+ return html;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Moby parse datatype service";
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 100;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualViewFactory.java b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualViewFactory.java
new file mode 100644
index 0000000..5179642
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomoby/view/MobyParseDatatypeContextualViewFactory.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ */
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.MobyParseDatatypeActivity;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+
+/**
+ * @author Stuart Owen
+ *
+ */
+public class MobyParseDatatypeContextualViewFactory implements
+ ContextualViewFactory<MobyParseDatatypeActivity> {
+
+ private ColourManager colourManager;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory#canHandle
+ * (java.lang.Object)
+ */
+ public boolean canHandle(Object activity) {
+ return activity instanceof MobyParseDatatypeActivity;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory#getView
+ * (java.lang.Object)
+ */
+ public List<ContextualView> getViews(MobyParseDatatypeActivity activity) {
+ return Arrays.asList(new ContextualView[] { new MobyParseDatatypeContextualView(activity,
+ colourManager) });
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/Add24.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/Add24.gif b/taverna-biomoby-activity-ui/src/main/resources/Add24.gif
new file mode 100644
index 0000000..fecc7a8
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/Add24.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/Cut24.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/Cut24.gif b/taverna-biomoby-activity-ui/src/main/resources/Cut24.gif
new file mode 100644
index 0000000..5c37d3a
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/Cut24.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/Information24.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/Information24.gif b/taverna-biomoby-activity-ui/src/main/resources/Information24.gif
new file mode 100644
index 0000000..16cb3de
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/Information24.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PartitionAlgorithmSetSPI
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PartitionAlgorithmSetSPI b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PartitionAlgorithmSetSPI
new file mode 100644
index 0000000..926b5e3
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PartitionAlgorithmSetSPI
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomoby.partition.BiomobyPartitionAlgorithmSetSPI
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PropertyExtractorSPI
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PropertyExtractorSPI b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PropertyExtractorSPI
new file mode 100644
index 0000000..afaed0e
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.PropertyExtractorSPI
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomoby.partition.BiomobyPropertyExtractor
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.QueryFactory
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.QueryFactory b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.QueryFactory
new file mode 100644
index 0000000..12241b2
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.partition.QueryFactory
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomoby.query.BiomobyQueryFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
new file mode 100644
index 0000000..604022f
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomoby.servicedescriptions.BiomobyServiceProvider
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
new file mode 100644
index 0000000..312b88c
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
@@ -0,0 +1,5 @@
+net.sf.taverna.t2.activities.biomoby.menu.BiomobyActivityDetailsMenuAction
+net.sf.taverna.t2.activities.biomoby.menu.BiomobyActivityParserMenuAction
+#net.sf.taverna.t2.activities.biomoby.actions.BiomobyAdvancedMenuAction
+net.sf.taverna.t2.activities.biomoby.menu.ConfigureBiomobyMenuAction
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
new file mode 100644
index 0000000..cca5a06
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
@@ -0,0 +1,2 @@
+net.sf.taverna.t2.activities.biomoby.query.BiomobyActivityIcon
+net.sf.taverna.t2.activities.biomoby.query.BiomobyObjectActivityIcon
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
new file mode 100644
index 0000000..43017c3
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
@@ -0,0 +1,3 @@
+net.sf.taverna.t2.activities.biomoby.view.BiomobyActivityContextualViewFactory
+net.sf.taverna.t2.activities.biomoby.view.BiomobyObjectActivityContextualViewFactory
+net.sf.taverna.t2.activities.biomoby.view.MobyParseDatatypeContextualViewFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context-osgi.xml b/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context-osgi.xml
new file mode 100644
index 0000000..c67a55b
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context-osgi.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="BiomobyActivityIcon" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI" />
+ <service ref="BiomobyObjectActivityIcon" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI" />
+
+ <service ref="BiomobyServiceProvider" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider" />
+
+ <service ref="BiomobyActivityDetailsMenuAction" auto-export="interfaces" />
+ <service ref="BiomobyActivityParserMenuAction" auto-export="interfaces" />
+ <service ref="ConfigureBiomobyMenuAction" auto-export="interfaces" />
+
+ <service ref="BiomobyActivityContextualViewFactory" interface="net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory" />
+ <service ref="BiomobyObjectActivityContextualViewFactory" interface="net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory" />
+ <service ref="MobyParseDatatypeContextualViewFactory" interface="net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory" />
+
+ <reference id="editManager" interface="net.sf.taverna.t2.workbench.edits.EditManager" />
+ <reference id="fileManager" interface="net.sf.taverna.t2.workbench.file.FileManager" />
+ <reference id="activityIconManager" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconManager" />
+ <reference id="colourManager" interface="net.sf.taverna.t2.workbench.configuration.colour.ColourManager" />
+ <reference id="serviceDescriptionRegistry" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context.xml b/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context.xml
new file mode 100644
index 0000000..87c832a
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/main/resources/META-INF/spring/biomoby-activity-ui-context.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="BiomobyActivityIcon" class="net.sf.taverna.t2.activities.biomoby.query.BiomobyActivityIcon" />
+ <bean id="BiomobyObjectActivityIcon" class="net.sf.taverna.t2.activities.biomoby.query.BiomobyObjectActivityIcon" />
+
+ <bean id="BiomobyServiceProvider" class="net.sf.taverna.t2.activities.biomoby.servicedescriptions.BiomobyServiceProvider">
+ <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" />
+ </bean>
+
+ <bean id="BiomobyActivityDetailsMenuAction" class="net.sf.taverna.t2.activities.biomoby.menu.BiomobyActivityDetailsMenuAction">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ </bean>
+ <bean id="BiomobyActivityParserMenuAction" class="net.sf.taverna.t2.activities.biomoby.menu.BiomobyActivityParserMenuAction">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ </bean>
+ <bean id="ConfigureBiomobyMenuAction" class="net.sf.taverna.t2.activities.biomoby.menu.ConfigureBiomobyMenuAction">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ </bean>
+
+ <bean id="BiomobyActivityContextualViewFactory" class="net.sf.taverna.t2.activities.biomoby.view.BiomobyActivityContextualViewFactory">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ <property name="colourManager" ref="colourManager" />
+ </bean>
+ <bean id="BiomobyObjectActivityContextualViewFactory" class="net.sf.taverna.t2.activities.biomoby.view.BiomobyObjectActivityContextualViewFactory">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="colourManager" ref="colourManager" />
+ </bean>
+ <bean id="MobyParseDatatypeContextualViewFactory" class="net.sf.taverna.t2.activities.biomoby.view.MobyParseDatatypeContextualViewFactory">
+ <property name="colourManager" ref="colourManager" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/Search24.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/Search24.gif b/taverna-biomoby-activity-ui/src/main/resources/Search24.gif
new file mode 100644
index 0000000..24fc7c1
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/Search24.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/authority.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/authority.png b/taverna-biomoby-activity-ui/src/main/resources/authority.png
new file mode 100644
index 0000000..33e239a
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/authority.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/biomoby_object.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/biomoby_object.png b/taverna-biomoby-activity-ui/src/main/resources/biomoby_object.png
new file mode 100644
index 0000000..73175f8
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/biomoby_object.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/collection.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/collection.png b/taverna-biomoby-activity-ui/src/main/resources/collection.png
new file mode 100644
index 0000000..feab424
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/collection.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/input.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/input.png b/taverna-biomoby-activity-ui/src/main/resources/input.png
new file mode 100644
index 0000000..d162a72
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/input.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/moby.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/moby.png b/taverna-biomoby-activity-ui/src/main/resources/moby.png
new file mode 100644
index 0000000..73175f8
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/moby.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/moby_small.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/moby_small.gif b/taverna-biomoby-activity-ui/src/main/resources/moby_small.gif
new file mode 100644
index 0000000..0fd0366
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/moby_small.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/output.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/output.png b/taverna-biomoby-activity-ui/src/main/resources/output.png
new file mode 100644
index 0000000..bd9cc94
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/output.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/parse.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/parse.png b/taverna-biomoby-activity-ui/src/main/resources/parse.png
new file mode 100644
index 0000000..49e2828
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/parse.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/registry.gif
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/registry.gif b/taverna-biomoby-activity-ui/src/main/resources/registry.gif
new file mode 100644
index 0000000..404b126
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/registry.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/main/resources/service.png
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/main/resources/service.png b/taverna-biomoby-activity-ui/src/main/resources/service.png
new file mode 100644
index 0000000..912efb2
Binary files /dev/null and b/taverna-biomoby-activity-ui/src/main/resources/service.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity-ui/src/test/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyContextualViewFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity-ui/src/test/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyContextualViewFactoryTest.java b/taverna-biomoby-activity-ui/src/test/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyContextualViewFactoryTest.java
new file mode 100644
index 0000000..a9c51c6
--- /dev/null
+++ b/taverna-biomoby-activity-ui/src/test/java/net/sf/taverna/t2/activities/biomoby/view/BiomobyContextualViewFactoryTest.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby.view;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivity;
+import net.sf.taverna.t2.activities.biomoby.BiomobyActivityConfigurationBean;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactoryRegistry;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class BiomobyContextualViewFactoryTest {
+ BiomobyActivity activity;
+ @Before
+ public void setup() throws ActivityConfigurationException {
+ activity=new BiomobyActivity() { //need to prevent the activity trying to configure itself, but store a copy of the config bean
+
+ @Override
+ public void configure(
+ BiomobyActivityConfigurationBean configurationBean)
+ throws ActivityConfigurationException {
+ this.configurationBean=configurationBean;
+ }
+
+ };
+ BiomobyActivityConfigurationBean b = new BiomobyActivityConfigurationBean();
+ b.setAuthorityName("a");
+ b.setMobyEndpoint("e");
+ b.setServiceName("s");
+ activity.configure(b);
+ }
+
+ @Test
+ public void testGetConfigureAction() throws Exception {
+ ContextualView view = new BiomobyActivityContextualView(activity, null, null, null, null);
+ //will be null because its not a valid activity so therefore has no secondaries
+ assertNull("The action should be null",view.getConfigureAction(null));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/pom.xml b/taverna-biomoby-activity/pom.xml
new file mode 100644
index 0000000..21f220e
--- /dev/null
+++ b/taverna-biomoby-activity/pom.xml
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>biomoby-activity</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Taverna 2 Biomoby Activity</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Embed-Transitive>true</Embed-Transitive>
+ <Embed-Dependency>jmoby;jmoby-dashboard</Embed-Dependency>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>workflowmodel-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>reference-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.biomoby</groupId>
+ <artifactId>jmoby</artifactId>
+ <version>${jmoby.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.biomoby</groupId>
+ <artifactId>taverna-for-moby</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xmlParserAPIs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.xml.ws</groupId>
+ <artifactId>jaxws-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.xml.soap</groupId>
+ <artifactId>saaj-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.biomoby</groupId>
+ <artifactId>jmoby-dashboard</artifactId>
+ <version>${jmoby.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>com.springsource.org.jdom</artifactId>
+ <version>${jdom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.httpclient</artifactId>
+ <version>${commons.httpclient.version}</version>
+ </dependency>
+ <!--<dependency> <groupId>org.apache.xmlcommons</groupId> <artifactId>com.springsource.org.apache.xmlcommons</artifactId>
+ <version>1.3.4</version> </dependency> -->
+ <!--<dependency> <groupId>javax.xml.ws</groupId> <artifactId>jaxws-api</artifactId>
+ <version>2.1</version> </dependency> -->
+ <!--<dependency> <groupId>com.sun.org.apache</groupId> <artifactId>jaxp-ri</artifactId>
+ <version>1.4</version> </dependency> -->
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>activity-test-utils</artifactId>
+ <version>${t2.activities.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-biomoby-activity.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/taverna/taverna-biomoby-activity.git</developerConnection>
+ <url>https://github.com/taverna/taverna-biomoby-activity/</url>
+ <tag>HEAD</tag>
+ </scm>
+
+</project>
[16/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
Revert "temporarily empty repository"
This reverts commit e13e3b7419f7c67ddf3c3e4184a59686639484cd.
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/commit/a87b4151
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/tree/a87b4151
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/diff/a87b4151
Branch: refs/heads/master
Commit: a87b4151c95077f7d75496abc5a9588a3a6bf129
Parents: e13e3b7
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Fri Feb 20 16:38:11 2015 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Fri Feb 20 16:38:11 2015 +0000
----------------------------------------------------------------------
pom.xml | 41 +
taverna-biomart-activity-ui/pom.xml | 94 +
.../BiomartActivityConfigurationAction.java | 74 +
.../actions/BiomartConfigurationPanel.java | 134 +
.../menu/BiomartConfigurationMenuAction.java | 68 +
.../BiomartActivityIcon.java | 59 +
.../BiomartServiceDescription.java | 146 +
.../BiomartServiceProvider.java | 147 +
.../BiomartServiceProviderConfig.java | 36 +
.../views/BiomartActivityContextualView.java | 117 +
.../views/BiomartActivityViewFactory.java | 86 +
...rvicedescriptions.ServiceDescriptionProvider | 1 +
.../net.sf.taverna.t2.ui.menu.MenuComponent | 1 +
...a.t2.workbench.activityicons.ActivityIconSPI | 1 +
...ntextualviews.activity.ContextualViewFactory | 1 +
.../spring/biomart-activity-ui-context-osgi.xml | 30 +
.../spring/biomart-activity-ui-context.xml | 29 +
.../src/main/resources/biomart.png | Bin 0 -> 3175 bytes
.../TestBiomartActivityContextualView.java | 94 +
.../src/test/resources/biomart-query.xml | 24 +
taverna-biomart-activity/pom.xml | 77 +
.../t2/activities/biomart/BiomartActivity.java | 351 ++
.../BiomartActivityConfigurationBean.java | 47 +
.../biomart/BiomartActivityFactory.java | 144 +
.../biomart/BiomartActivityHealthChecker.java | 76 +
...averna.t2.workflowmodel.health.HealthChecker | 1 +
.../spring/biomart-activity-context-osgi.xml | 15 +
.../spring/biomart-activity-context.xml | 13 +
.../src/main/resources/schema.json | 19 +
.../biomart/BiomartActivityFactoryTest.java | 65 +
.../src/test/resources/biomart-query.xml | 17 +
taverna-biomart-martservice/pom.xml | 105 +
.../org/biomart/martservice/DatasetLink.java | 220 ++
.../org/biomart/martservice/MartDataset.java | 342 ++
.../java/org/biomart/martservice/MartQuery.java | 436 +++
.../org/biomart/martservice/MartRegistry.java | 96 +
.../org/biomart/martservice/MartService.java | 709 ++++
.../martservice/MartServiceException.java | 86 +
.../biomart/martservice/MartServiceUtils.java | 725 ++++
.../martservice/MartServiceXMLHandler.java | 390 ++
.../biomart/martservice/MartURLLocation.java | 422 +++
.../org/biomart/martservice/ResultReceiver.java | 61 +
.../martservice/ResultReceiverException.java | 85 +
.../config/QueryConfigController.java | 388 ++
.../martservice/config/QueryConfigUtils.java | 598 +++
.../config/event/QueryComponentAdapter.java | 109 +
.../config/event/QueryComponentEvent.java | 120 +
.../config/event/QueryComponentListener.java | 104 +
.../config/ui/ConfigDisplayObject.java | 125 +
.../martservice/config/ui/ExpandableBox.java | 204 +
.../martservice/config/ui/MartServiceIcons.java | 104 +
.../ui/MartServiceQueryConfigUIFactory.java | 3543 ++++++++++++++++++
.../martservice/config/ui/MinimalLayout.java | 158 +
.../martservice/config/ui/QueryComponent.java | 342 ++
.../config/ui/QueryConfigUIFactory.java | 345 ++
.../biomart/martservice/query/Attribute.java | 198 +
.../org/biomart/martservice/query/Dataset.java | 309 ++
.../org/biomart/martservice/query/Filter.java | 243 ++
.../org/biomart/martservice/query/Link.java | 181 +
.../org/biomart/martservice/query/Query.java | 555 +++
.../martservice/query/QueryListener.java | 108 +
.../martservice/query/QueryXMLHandler.java | 332 ++
.../biomart/martservice/config/ui/contract.gif | Bin 0 -> 90 bytes
.../biomart/martservice/config/ui/expand.gif | Bin 0 -> 93 bytes
.../martservice/config/ui/gene_schematic.gif | Bin 0 -> 734 bytes
.../config/ui/gene_schematic_3utr.gif | Bin 0 -> 717 bytes
.../config/ui/gene_schematic_5utr.gif | Bin 0 -> 722 bytes
.../config/ui/gene_schematic_cdna.gif | Bin 0 -> 743 bytes
.../config/ui/gene_schematic_coding.gif | Bin 0 -> 760 bytes
.../ui/gene_schematic_coding_gene_flank.gif | Bin 0 -> 715 bytes
.../gene_schematic_coding_transcript_flank.gif | Bin 0 -> 765 bytes
.../config/ui/gene_schematic_gene_exon.gif | Bin 0 -> 504 bytes
.../ui/gene_schematic_gene_exon_intron.gif | Bin 0 -> 710 bytes
.../config/ui/gene_schematic_gene_flank.gif | Bin 0 -> 710 bytes
.../config/ui/gene_schematic_peptide.gif | Bin 0 -> 760 bytes
.../ui/gene_schematic_transcript_exon.gif | Bin 0 -> 920 bytes
.../gene_schematic_transcript_exon_intron.gif | Bin 0 -> 716 bytes
.../ui/gene_schematic_transcript_flank.gif | Bin 0 -> 751 bytes
.../biomart/martservice/MartDatasetTest.java | 335 ++
.../biomart/martservice/MartRegistryTest.java | 113 +
.../martservice/MartServiceUtilsTest.java | 65 +
.../martservice/MartServiceXMLHandlerTest.java | 218 ++
.../martservice/MartURLLocationTest.java | 255 ++
.../config/event/QueryComponentEventTest.java | 131 +
.../config/ui/MartServiceIconsTest.java | 77 +
.../martservice/query/AttributeTest.java | 164 +
.../biomart/martservice/query/DatasetTest.java | 308 ++
.../biomart/martservice/query/FilterTest.java | 242 ++
.../biomart/martservice/query/QueryTest.java | 303 ++
taverna-biomoby-activity-ui/pom.xml | 86 +
.../biomoby/actions/AddParserActionHelper.java | 280 ++
.../BioMobyObjectTreeCustomRenderer.java | 97 +
.../BioMobyServiceTreeCustomRenderer.java | 86 +
.../biomoby/actions/BiomobyActionHelper.java | 852 +++++
.../BiomobyActivityConfigurationAction.java | 60 +
.../actions/BiomobyObjectActionHelper.java | 787 ++++
.../biomoby/actions/BiomobyScavengerDialog.java | 136 +
.../actions/MobyObjectDetailsAction.java | 83 +
.../biomoby/actions/MobyObjectTreeNode.java | 50 +
.../activities/biomoby/actions/MobyPanel.java | 136 +
.../biomoby/actions/MobyParserAction.java | 70 +
.../actions/MobyServiceDetailsAction.java | 65 +
.../biomoby/actions/MobyServiceTreeNode.java | 42 +
.../activities/biomoby/actions/PopupThread.java | 34 +
.../biomoby/actions/SimpleActionFrame.java | 46 +
.../BiomobyDatatypeDescription.java | 143 +
.../edits/AddBiomobyCollectionDataTypeEdit.java | 60 +
.../edits/AddBiomobyConsumingServiceEdit.java | 236 ++
.../biomoby/edits/AddBiomobyDataTypeEdit.java | 207 +
.../biomoby/edits/AddMobyParseDatatypeEdit.java | 220 ++
.../biomoby/edits/AddUpstreamObjectEdit.java | 216 ++
.../menu/BiomobyActivityDetailsMenuAction.java | 40 +
.../menu/BiomobyActivityParserMenuAction.java | 41 +
.../menu/ConfigureBiomobyMenuAction.java | 52 +
.../biomoby/query/BiomobyActivityIcon.java | 36 +
.../biomoby/query/BiomobyActivityItem.java | 94 +
.../query/BiomobyObjectActivityIcon.java | 32 +
.../query/BiomobyObjectActivityItem.java | 76 +
.../biomoby/query/BiomobyQueryHelper.java | 270 ++
.../t2/activities/biomoby/query/CacheImpl.java | 568 +++
.../BiomobyServiceDescription.java | 137 +
.../BiomobyServiceProvider.java | 121 +
.../BiomobyServiceProviderConfig.java | 37 +
.../biomoby/ui/AddBiomobyDialogue.java | 94 +
.../biomoby/ui/BiomobyObjectTree.java | 635 ++++
.../activities/biomoby/ui/DatatypeMenuItem.java | 196 +
.../view/BiomobyActivityContextualView.java | 106 +
.../BiomobyActivityContextualViewFactory.java | 50 +
.../biomoby/view/BiomobyConfigView.java | 108 +
.../BiomobyObjectActivityContextualView.java | 95 +
...mobyObjectActivityContextualViewFactory.java | 67 +
.../view/MobyParseDatatypeContextualView.java | 62 +
.../MobyParseDatatypeContextualViewFactory.java | 69 +
.../src/main/resources/Add24.gif | Bin 0 -> 470 bytes
.../src/main/resources/Cut24.gif | Bin 0 -> 1193 bytes
.../src/main/resources/Information24.gif | Bin 0 -> 1328 bytes
...averna.t2.partition.PartitionAlgorithmSetSPI | 1 +
...sf.taverna.t2.partition.PropertyExtractorSPI | 1 +
.../net.sf.taverna.t2.partition.QueryFactory | 1 +
...rvicedescriptions.ServiceDescriptionProvider | 1 +
.../net.sf.taverna.t2.ui.menu.MenuComponent | 5 +
...a.t2.workbench.activityicons.ActivityIconSPI | 2 +
...ntextualviews.activity.ContextualViewFactory | 3 +
.../spring/biomoby-activity-ui-context-osgi.xml | 28 +
.../spring/biomoby-activity-ui-context.xml | 42 +
.../src/main/resources/Search24.gif | Bin 0 -> 820 bytes
.../src/main/resources/authority.png | Bin 0 -> 481 bytes
.../src/main/resources/biomoby_object.png | Bin 0 -> 981 bytes
.../src/main/resources/collection.png | Bin 0 -> 628 bytes
.../src/main/resources/input.png | Bin 0 -> 489 bytes
.../src/main/resources/moby.png | Bin 0 -> 981 bytes
.../src/main/resources/moby_small.gif | Bin 0 -> 787 bytes
.../src/main/resources/output.png | Bin 0 -> 511 bytes
.../src/main/resources/parse.png | Bin 0 -> 227 bytes
.../src/main/resources/registry.gif | Bin 0 -> 935 bytes
.../src/main/resources/service.png | Bin 0 -> 441 bytes
.../view/BiomobyContextualViewFactoryTest.java | 49 +
taverna-biomoby-activity/pom.xml | 142 +
.../t2/activities/biomoby/BiomobyActivity.java | 1319 +++++++
.../BiomobyActivityConfigurationBean.java | 142 +
.../biomoby/BiomobyActivityFactory.java | 49 +
.../biomoby/BiomobyActivityHealthChecker.java | 45 +
.../t2/activities/biomoby/BiomobyCache.java | 78 +
.../biomoby/BiomobyObjectActivity.java | 545 +++
.../BiomobyObjectActivityConfigurationBean.java | 81 +
.../biomoby/BiomobyObjectActivityFactory.java | 49 +
.../BiomobyObjectActivityHealthChecker.java | 57 +
.../biomoby/ExecuteAsyncCgiService.java | 517 +++
.../biomoby/ExecuteAsyncMobyService.java | 695 ++++
.../activities/biomoby/ExecuteCgiService.java | 70 +
.../activities/biomoby/ExecuteMobyService.java | 38 +
.../activities/biomoby/GetOntologyThread.java | 59 +
.../biomoby/MobyParseDatatypeActivity.java | 417 +++
...yParseDatatypeActivityConfigurationBean.java | 81 +
.../MobyParseDatatypeActivityFactory.java | 49 +
.../MobyParseDatatypeActivityHealthChecker.java | 58 +
.../t2/activities/biomoby/ParseMobyXML.java | 192 +
.../activities/biomoby/RetrieveWsdlThread.java | 57 +
.../t2/activities/biomoby/XMLUtilities.java | 1927 ++++++++++
...averna.t2.workflowmodel.health.HealthChecker | 3 +
.../spring/biomoby-activity-context-osgi.xml | 17 +
.../spring/biomoby-activity-context.xml | 14 +
.../BiomobyActivityHealthCheckerTest.java | 45 +
.../BiomobyObjectActivityHealthCheckerTest.java | 45 +
...yParseDatatypeActivityHealthCheckerTest.java | 45 +
taverna-ncbi-activity-ui/pom.xml | 49 +
.../spring/ncbi-activity-ui-context-osgi.xml | 9 +
.../spring/ncbi-activity-ui-context.xml | 6 +
.../src/main/resources/ncbi_services | 0
.../src/main/resources/wsdl.png | Bin 0 -> 748 bytes
taverna-soaplab-activity-ui/pom.xml | 103 +
.../SoaplabActivityConfigurationAction.java | 68 +
.../actions/SoaplabConfigurationPanel.java | 183 +
.../ConfigureSoaplabActivityMenuAction.java | 54 +
.../MissingSoaplabException.java | 63 +
.../SoaplabActivityIcon.java | 60 +
.../servicedescriptions/SoaplabCategory.java | 80 +
.../SoaplabScavengerAgent.java | 144 +
.../SoaplabServiceDescription.java | 131 +
.../SoaplabServiceProvider.java | 183 +
.../SoaplabServiceProviderConfig.java | 38 +
.../views/SoaplabActivityContextualView.java | 156 +
.../views/SoaplabActivityViewFactory.java | 73 +
...rvicedescriptions.ServiceDescriptionProvider | 1 +
.../net.sf.taverna.t2.ui.menu.MenuComponent | 1 +
...a.t2.workbench.activityicons.ActivityIconSPI | 1 +
...ntextualviews.activity.ContextualViewFactory | 1 +
.../spring/soaplab-activity-ui-context-osgi.xml | 28 +
.../spring/soaplab-activity-ui-context.xml | 27 +
.../main/resources/analysis_metadata_2_html.xsl | 96 +
.../src/main/resources/soaplab.png | Bin 0 -> 701 bytes
.../TestSoaplabActivityContextualView.java | 61 +
taverna-soaplab-activity/pom.xml | 80 +
.../sf/taverna/t2/activities/soaplab/Soap.java | 82 +
.../t2/activities/soaplab/SoaplabActivity.java | 413 ++
.../SoaplabActivityConfigurationBean.java | 119 +
.../soaplab/SoaplabActivityFactory.java | 216 ++
.../soaplab/SoaplabActivityHealthChecker.java | 66 +
...averna.t2.workflowmodel.health.HealthChecker | 1 +
.../spring/soaplab-activity-context-osgi.xml | 15 +
.../spring/soaplab-activity-context.xml | 12 +
.../src/main/resources/schema.json | 40 +
.../SoaplabActivityConfigurationBeanTest.java | 92 +
.../activities/soaplab/SoaplabActivityTest.java | 127 +
224 files changed, 32788 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5102f18
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.taverna.bioinformatics</groupId>
+ <artifactId>taverna-plugin-bioinformatics</artifactId>
+ <version>3.1.0-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Taverna Plugin for Bioinformatics</name>
+ <properties>
+ <taverna.language.version>0.15.0-incubating-SNAPSHOT</taverna.language.version>
+ <taverna.osgi.version>0.2.0-incubating-SNAPSHOT</taverna.osgi.version>
+ <taverna.engine.version>3.1.0-incubating-SNAPSHOT</taverna.engine.version>
+ <taverna.commonactivities.version>2.1.0-incubating-SNAPSHOT</taverna.commonactivities.version>
+ </properties>
+ <modules>
+ <module>taverna-biomart-activity</module>
+ <module>taverna-biomart-activity-ui</module>
+ <module>taverna-biomart-martservice</module>
+ <module>taverna-biomoby-activity</module>
+ <module>taverna-biomoby-activity-ui</module>
+ <module>taverna-ncbi-activity-ui</module>
+ <module>taverna-soaplab-activity</module>
+ <module>taverna-soaplab-activity-ui</module>
+ </modules>
+ <repositories>
+ <repository>
+ <id>taverna-incubating</id>
+ <name>Apache Taverna incubating Repository</name>
+ <url>http://repository.mygrid.org.uk/artifactory/incubator-snapshot-local/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ </repository>
+ </repositories>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/pom.xml b/taverna-biomart-activity-ui/pom.xml
new file mode 100644
index 0000000..8465101
--- /dev/null
+++ b/taverna-biomart-activity-ui/pom.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.ui-activities</groupId>
+ <artifactId>biomart-activity-ui</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Taverna 2 Biomart Activity UI</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Import-Package>net.sf.taverna.t2.ui.menu,*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>biomart-activity</artifactId>
+ <version>${t2.activities.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-icons-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-palette-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>contextual-views-api</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-api</groupId>
+ <artifactId>activity-tools</artifactId>
+ <version>${t2.ui.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>uk.org.taverna.configuration</groupId>
+ <artifactId>taverna-app-configuration-api</artifactId>
+ <version>${taverna.configuration.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.ui-impl</groupId>
+ <artifactId>configuration-impl</artifactId>
+ <version>${t2.ui.impl.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository
+ </url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
new file mode 100644
index 0000000..a0b51e7
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.actions;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
+import uk.org.taverna.commons.services.ServiceRegistry;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+@SuppressWarnings("serial")
+public class BiomartActivityConfigurationAction extends ActivityConfigurationAction {
+
+ public static final String CONFIGURE_BIOMART = "Configure Biomart query";
+ private final EditManager editManager;
+ private final FileManager fileManager;
+ private final ApplicationConfiguration applicationConfiguration;
+ private final ServiceRegistry serviceRegistry;
+
+ public BiomartActivityConfigurationAction(Activity activity, Frame owner,
+ EditManager editManager, FileManager fileManager, ActivityIconManager activityIconManager,
+ ApplicationConfiguration applicationConfiguration, ServiceDescriptionRegistry serviceDescriptionRegistry,
+ ServiceRegistry serviceRegistry) {
+ super(activity, activityIconManager, serviceDescriptionRegistry);
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ this.applicationConfiguration = applicationConfiguration;
+ this.serviceRegistry = serviceRegistry;
+ putValue(Action.NAME, CONFIGURE_BIOMART);
+ }
+
+ public void actionPerformed(ActionEvent action) {
+ ActivityConfigurationDialog currentDialog = ActivityConfigurationAction.getDialog(getActivity());
+ if (currentDialog != null) {
+ currentDialog.toFront();
+ return;
+ }
+
+ final BiomartConfigurationPanel configurationPanel = new BiomartConfigurationPanel(
+ getActivity(), applicationConfiguration, serviceRegistry);
+ final ActivityConfigurationDialog dialog = new ActivityConfigurationDialog(
+ getActivity(), configurationPanel, editManager);
+
+ ActivityConfigurationAction.setDialog(getActivity(), dialog, fileManager);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
new file mode 100644
index 0000000..2b6f662
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.actions;
+
+import java.awt.Dimension;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URI;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationPanel;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartService;
+import org.biomart.martservice.MartServiceException;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.biomart.martservice.config.QueryConfigController;
+import org.biomart.martservice.config.ui.MartServiceQueryConfigUIFactory;
+import org.biomart.martservice.config.ui.QueryConfigUIFactory;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+
+import uk.org.taverna.commons.services.ServiceRegistry;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+public class BiomartConfigurationPanel extends ActivityConfigurationPanel {
+ private static Logger logger = Logger.getLogger(BiomartConfigurationPanel.class);
+
+ private static final long serialVersionUID = 1884045346293327621L;
+
+ public static final URI ACTIVITY_TYPE = URI.create("http://ns.taverna.org.uk/2010/activity/biomart");
+
+ private String configurationString;
+
+ private MartQuery biomartQuery;
+
+ private static XMLOutputter outputter = new XMLOutputter();
+
+ private final ApplicationConfiguration applicationConfiguration;
+
+ private final ServiceRegistry serviceRegistry;
+
+ public BiomartConfigurationPanel(Activity activity, ApplicationConfiguration applicationConfiguration,
+ ServiceRegistry serviceRegistry) {
+ super(activity);
+ this.applicationConfiguration = applicationConfiguration;
+ this.serviceRegistry = serviceRegistry;
+ initialise();
+ }
+
+ protected void initialise() {
+ super.initialise();
+ removeAll();
+
+ configurationString = getProperty("martQuery");
+ Element martQuery = null;
+ try {
+ martQuery = new SAXBuilder().build(new StringReader(configurationString)).getRootElement();
+ } catch (JDOMException | IOException e) {
+ logger.warn(e);
+ }
+ setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
+
+ biomartQuery = MartServiceXMLHandler.elementToMartQuery(martQuery, null);
+ MartService service = biomartQuery.getMartService();
+
+ File homeRoot=applicationConfiguration.getApplicationHomeDir();
+ if (homeRoot==null) {
+ logger.error("unable to determine application home for biomart cache");
+ homeRoot=new File(System.getProperty("java.io.tmpdir"));
+ }
+ File cache=new File(homeRoot,"t2-biomart-activity");
+ service.setCacheDirectory(new File(cache,"cache"));
+ logger.info("Biomart is using cache directory:"+cache.getAbsolutePath());
+
+ QueryConfigController controller = new QueryConfigController(biomartQuery);
+ try {
+ QueryConfigUIFactory queryConfigUIFactory = new MartServiceQueryConfigUIFactory(
+ service, controller, biomartQuery.getMartDataset());
+ add(queryConfigUIFactory.getDatasetConfigUI());
+ add(Box.createGlue());
+ } catch (MartServiceException e) {
+ add(new JLabel("Error reading configuration properties"));
+ add(new JLabel(e.getMessage()));
+ add(Box.createGlue());
+ }
+ this.setPreferredSize(new Dimension(900,500));
+ this.validate();
+ }
+
+ public Element getQuery() {
+ return MartServiceXMLHandler.martQueryToElement(biomartQuery, null);
+ }
+
+ @Override
+ public void noteConfiguration() {
+ setProperty("martQuery", outputter.outputString(new Document(getQuery())));
+ configureInputPorts(serviceRegistry);
+ configureOutputPorts(serviceRegistry);
+ }
+
+ @Override
+ public boolean checkValues() {
+ // TODO Not yet done
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/menu/BiomartConfigurationMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/menu/BiomartConfigurationMenuAction.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/menu/BiomartConfigurationMenuAction.java
new file mode 100644
index 0000000..775ce95
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/menu/BiomartConfigurationMenuAction.java
@@ -0,0 +1,68 @@
+package net.sf.taverna.t2.activities.biomart.menu;
+
+import java.net.URI;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.biomart.actions.BiomartActivityConfigurationAction;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.ui.menu.ContextualMenuComponent;
+import net.sf.taverna.t2.ui.menu.MenuComponent;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.activitytools.AbstractConfigureActivityMenuAction;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import uk.org.taverna.commons.services.ServiceRegistry;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+public class BiomartConfigurationMenuAction extends AbstractConfigureActivityMenuAction implements
+ MenuComponent, ContextualMenuComponent {
+
+ private static final URI BIOMART_ACTIVITY = URI
+ .create("http://ns.taverna.org.uk/2010/activity/biomart");
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+ private ApplicationConfiguration applicationConfiguration;
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+ private ServiceRegistry serviceRegistry;
+
+ public BiomartConfigurationMenuAction() {
+ super(BIOMART_ACTIVITY);
+ }
+
+ @Override
+ protected Action createAction() {
+ BiomartActivityConfigurationAction configAction = new BiomartActivityConfigurationAction(
+ findActivity(), getParentFrame(), editManager, fileManager, activityIconManager,
+ applicationConfiguration, serviceDescriptionRegistry, serviceRegistry);
+ configAction.putValue(Action.NAME, BiomartActivityConfigurationAction.CONFIGURE_BIOMART);
+ addMenuDots(configAction);
+ return configAction;
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+ public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+ public void setServiceRegistry(ServiceRegistry serviceRegistry) {
+ this.serviceRegistry = serviceRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartActivityIcon.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartActivityIcon.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartActivityIcon.java
new file mode 100644
index 0000000..845665e
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartActivityIcon.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.servicedescriptions;
+
+import java.net.URI;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI;
+
+/**
+ *
+ * @author Alex Nenadic
+ * @author Alan R Williams
+ *
+ */
+public class BiomartActivityIcon implements ActivityIconSPI {
+
+ private static final URI BIOMART_ACTIVITY = URI.create("http://ns.taverna.org.uk/2010/activity/biomart");
+
+ static Icon icon = null;
+
+ public int canProvideIconScore(URI activityType) {
+ if (BIOMART_ACTIVITY.equals(activityType))
+ return DEFAULT_ICON + 1;
+ else
+ return NO_ICON;
+ }
+
+ public Icon getIcon(URI activityType) {
+ return getBiomartIcon();
+ }
+
+ public static Icon getBiomartIcon() {
+ if (icon == null) {
+ icon = new ImageIcon(BiomartActivityIcon.class.getResource("/biomart.png"));
+ }
+ return icon;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
new file mode 100644
index 0000000..ca50019
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
@@ -0,0 +1,146 @@
+/* Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.servicedescriptions;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.XMLOutputter;
+
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * @author alanrw
+ * @author David Withers
+ */
+public class BiomartServiceDescription extends ServiceDescription {
+
+ public static final URI ACTIVITY_TYPE = URI.create("http://ns.taverna.org.uk/2010/activity/biomart");
+
+ private String url;
+ private String dataset;
+ private String location;
+
+ private static final String BIOMART = "Biomart @ ";
+ private Element martQuery;
+
+ public Element getMartQuery() {
+ return martQuery;
+ }
+
+ /**
+ * @return the url
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * @param url
+ * the url to set
+ */
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ /**
+ * @return the dataset
+ */
+ public String getDataset() {
+ return dataset;
+ }
+
+ /**
+ * @param dataset
+ * the dataset to set
+ */
+ public void setDataset(String dataset) {
+ this.dataset = dataset;
+ }
+
+ /**
+ * @return the location
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /**
+ * @param location
+ * the location to set
+ */
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public void setMartQuery(Element martQuery) {
+ this.martQuery = martQuery;
+ }
+
+ @Override
+ public URI getActivityType() {
+ return ACTIVITY_TYPE;
+ }
+
+ @Override
+ public Configuration getActivityConfiguration() {
+ Configuration configuration = new Configuration();
+ configuration.setType(ACTIVITY_TYPE.resolve("#Config"));
+ String queryText = new XMLOutputter().outputString(new Document(martQuery));
+ ((ObjectNode) configuration.getJson()).put("martQuery", queryText);
+ return configuration;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return BiomartActivityIcon.getBiomartIcon();
+ }
+
+ @Override
+ public String getName() {
+ return dataset;
+ }
+
+ @Override
+ public List<? extends Comparable<?>> getPath() {
+ List<String> result;
+ result = Arrays.asList(BIOMART + url, location);
+ return result;
+ }
+
+ @Override
+ protected List<Object> getIdentifyingData() {
+ return Arrays.<Object> asList(getUrl(), getLocation(), getDataset());
+ }
+
+ @Override
+ public boolean isTemplateService() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProvider.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProvider.java
new file mode 100644
index 0000000..712e8d8
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProvider.java
@@ -0,0 +1,147 @@
+/**
+ *
+ */
+package net.sf.taverna.t2.activities.biomart.servicedescriptions;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+
+import org.biomart.martservice.MartDataset;
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartRegistry;
+import org.biomart.martservice.MartService;
+import org.biomart.martservice.MartServiceException;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.biomart.martservice.MartURLLocation;
+
+/**
+ * @author alanrw
+ * @author David Withers
+ */
+public class BiomartServiceProvider extends AbstractConfigurableServiceProvider<BiomartServiceProviderConfig> {
+
+ private static final String TAVERNA = "taverna";
+ private static final String BIOMART_SERVICE = "Biomart service";
+
+ private static final URI providerId = URI
+ .create("http://taverna.sf.net/2010/service-provider/biomart");
+
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public BiomartServiceProvider() {
+ super(new BiomartServiceProviderConfig("http://somehost/biomart"));
+ }
+
+ public void findServiceDescriptionsAsync(
+ FindServiceDescriptionsCallBack callBack) {
+ List<ServiceDescription> descriptions = new ArrayList<ServiceDescription>();
+ String url = serviceProviderConfig.getUrl();
+ callBack.status("About to parse biomart:" + url);
+ try {
+ MartService martService = MartService
+ .getMartService(getBiomartServiceLocation(url));
+ martService.setRequestId(TAVERNA);
+ MartRegistry registry = martService.getRegistry();
+ MartURLLocation[] martURLLocations = registry.getMartURLLocations();
+ for (MartURLLocation martURLLocation : martURLLocations) {
+ if (martURLLocation.isVisible()) {
+
+ MartDataset[] datasets = martService
+ .getDatasets(martURLLocation);
+ Arrays.sort(datasets, MartDataset.getDisplayComparator());
+ for (MartDataset dataset : datasets) {
+ if (dataset.isVisible()) {
+ BiomartServiceDescription item = new BiomartServiceDescription();
+ item.setUrl(martService.getLocation());
+ item.setLocation(martURLLocation.getDisplayName());
+ item.setDataset(dataset.getName());
+ item.setDescription(dataset.getDisplayName());
+ MartQuery biomartQuery = new MartQuery(martService,
+ dataset, TAVERNA);
+ item.setMartQuery(MartServiceXMLHandler.martQueryToElement(biomartQuery, null));
+ descriptions.add(item);
+ }
+ }
+ if (descriptions.size() > 0) {
+ callBack.partialResults(descriptions);
+ descriptions.clear();
+ }
+ }
+ }
+ callBack.finished();
+ }
+ catch (MartServiceException e) {
+ callBack.fail("Failed to load Biomart from " + url, e);
+ }
+ }
+
+ public Icon getIcon() {
+ return BiomartActivityIcon.getBiomartIcon();
+ }
+
+ public String getName() {
+ return BIOMART_SERVICE;
+ }
+
+ /**
+ * Attempts to construct a valid MartService URL from the location given.
+ *
+ * @param biomartLocation
+ * @return a (hopefully) valid MartService URL
+ */
+ private String getBiomartServiceLocation(String biomartLocation) {
+ StringBuffer sb = new StringBuffer();
+ if (biomartLocation.endsWith("martservice")) {
+ sb.append(biomartLocation);
+ } else if (biomartLocation.endsWith("martview")) {
+ sb.append(biomartLocation.substring(0, biomartLocation
+ .lastIndexOf("martview")));
+ sb.append("martservice");
+ } else if (biomartLocation.endsWith("/")) {
+ sb.append(biomartLocation);
+ sb.append("martservice");
+ } else {
+ sb.append(biomartLocation);
+ sb.append("/martservice");
+ }
+ return sb.toString();
+ }
+
+ public List<BiomartServiceProviderConfig> getDefaultConfigurations() {
+
+ List<BiomartServiceProviderConfig> defaults = new ArrayList<BiomartServiceProviderConfig>();
+
+ // If defaults have failed to load from a configuration file then load them here.
+ if (!serviceDescriptionRegistry.isDefaultSystemConfigurableProvidersLoaded()){
+ defaults.add(new BiomartServiceProviderConfig(
+ "http://www.biomart.org/biomart/martservice"));
+ } // else return an empty list
+
+ return defaults;
+
+ }
+
+ @Override
+ protected List<? extends Object> getIdentifyingData() {
+ List<String> result;
+ result = Arrays.asList(getConfiguration().getUrl());
+ return result;
+ }
+
+ public String getId() {
+ return providerId.toString();
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProviderConfig.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProviderConfig.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProviderConfig.java
new file mode 100644
index 0000000..9891fae
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceProviderConfig.java
@@ -0,0 +1,36 @@
+/**
+ *
+ */
+package net.sf.taverna.t2.activities.biomart.servicedescriptions;
+
+import net.sf.taverna.t2.lang.beans.PropertyAnnotated;
+import net.sf.taverna.t2.lang.beans.PropertyAnnotation;
+
+/**
+ * @author alanrw
+ *
+ */
+public class BiomartServiceProviderConfig extends PropertyAnnotated {
+
+ private String url;
+
+ public BiomartServiceProviderConfig() {
+ }
+
+ public BiomartServiceProviderConfig(String url) {
+ this.url = url.trim();
+ }
+
+ @PropertyAnnotation(displayName = "Biomart location", preferred = true)
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url.trim();
+ }
+
+ public String toString() {
+ return getUrl();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
new file mode 100644
index 0000000..87a2294
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.views;
+
+import java.awt.Frame;
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.biomart.actions.BiomartActivityConfigurationAction;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+
+import org.biomart.martservice.MartQuery;
+import org.biomart.martservice.MartServiceXMLHandler;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Filter;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import uk.org.taverna.commons.services.ServiceRegistry;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+@SuppressWarnings("serial")
+public class BiomartActivityContextualView extends HTMLBasedActivityContextualView {
+
+ private final EditManager editManager;
+ private final FileManager fileManager;
+ private final ActivityIconManager activityIconManager;
+ private final ApplicationConfiguration applicationConfiguration;
+ private final ServiceDescriptionRegistry serviceDescriptionRegistry;
+ private final ServiceRegistry serviceRegistry;
+
+ public BiomartActivityContextualView(Activity activity, EditManager editManager,
+ FileManager fileManager, ActivityIconManager activityIconManager,
+ ColourManager colourManager, ApplicationConfiguration applicationConfiguration,
+ ServiceDescriptionRegistry serviceDescriptionRegistry, ServiceRegistry serviceRegistry) {
+ super(activity, colourManager);
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ this.activityIconManager = activityIconManager;
+ this.applicationConfiguration = applicationConfiguration;
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ this.serviceRegistry = serviceRegistry;
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ String queryText = getConfigBean().getJson().get("martQuery").textValue();
+ Element martQuery = null;
+ try {
+ martQuery = new SAXBuilder().build(new StringReader(queryText)).getRootElement();
+ } catch (JDOMException | IOException e) {
+ }
+ MartQuery q = MartServiceXMLHandler.elementToMartQuery(martQuery, null);
+ String html = "<tr><td>URL</td><td>" + q.getMartService().getLocation() + "</td></tr>";
+ html += "<tr><td>Location</td><td>"
+ + q.getMartDataset().getMartURLLocation().getDisplayName() + "</td></tr>";
+ boolean firstFilter = true;
+ for (Filter filter : q.getQuery().getFilters()) {
+ html += firstFilter ? "<tr><td>Filter</td><td>" : "<tr><td></td></td>";
+ firstFilter = false;
+ html += filter.getName() + "</td></tr>";
+ }
+ boolean firstAttribute = true;
+ for (Attribute attribute : q.getQuery().getAttributes()) {
+ html += firstAttribute ? "<tr><td>Attribute</td><td>" : "<tr><td></td><td>";
+ firstAttribute = false;
+ html += attribute.getName() + "</td></tr>";
+ }
+ html += "<tr><td>Dataset</td><td>" + q.getMartDataset().getDisplayName() + "</td></tr>";
+ return html;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Biomart service";
+ }
+
+ @Override
+ public Action getConfigureAction(Frame owner) {
+ return new BiomartActivityConfigurationAction(getActivity(), owner, editManager,
+ fileManager, activityIconManager, applicationConfiguration,
+ serviceDescriptionRegistry, serviceRegistry);
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 100;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
new file mode 100644
index 0000000..ad8321a
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomart.views;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.biomart.servicedescriptions.BiomartServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+import uk.org.taverna.commons.services.ServiceRegistry;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+public class BiomartActivityViewFactory implements ContextualViewFactory<Activity> {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+ private ColourManager colourManager;
+ private ApplicationConfiguration applicationConfiguration;
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+ private ServiceRegistry serviceRegistry;
+
+ public boolean canHandle(Object object) {
+ return object instanceof Activity && ((Activity) object).getType().equals(BiomartServiceDescription.ACTIVITY_TYPE);
+ }
+
+ public List<ContextualView> getViews(Activity activity) {
+ return Arrays.asList(new ContextualView[] { new BiomartActivityContextualView(activity,
+ editManager, fileManager, activityIconManager, colourManager,
+ applicationConfiguration, serviceDescriptionRegistry, serviceRegistry) });
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+ public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+ public void setServiceRegistry(ServiceRegistry serviceRegistry) {
+ this.serviceRegistry = serviceRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
new file mode 100644
index 0000000..637d76a
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomart.servicedescriptions.BiomartServiceProvider
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
new file mode 100644
index 0000000..dbff4b7
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomart.menu.BiomartConfigurationMenuAction
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
new file mode 100644
index 0000000..e8506ef
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomart.servicedescriptions.BiomartActivityIcon
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
new file mode 100644
index 0000000..355b9ef
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.biomart.views.BiomartActivityViewFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context-osgi.xml b/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context-osgi.xml
new file mode 100644
index 0000000..e5ea96b
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context-osgi.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="BiomartActivityIcon" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI" />
+
+ <service ref="BiomartServiceProvider">
+ <interfaces>
+ <beans:value>net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider</beans:value>
+ <beans:value>net.sf.taverna.t2.servicedescriptions.ConfigurableServiceProvider</beans:value>
+ </interfaces>
+ </service>
+
+ <service ref="BiomartConfigurationMenuAction" auto-export="interfaces" />
+
+ <service ref="BiomartActivityViewFactory" interface="net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory" />
+
+ <reference id="editManager" interface="net.sf.taverna.t2.workbench.edits.EditManager" />
+ <reference id="fileManager" interface="net.sf.taverna.t2.workbench.file.FileManager" />
+ <reference id="activityIconManager" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconManager" />
+ <reference id="colourManager" interface="net.sf.taverna.t2.workbench.configuration.colour.ColourManager" />
+ <reference id="serviceDescriptionRegistry" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry"/>
+ <reference id="applicationConfiguration" interface="uk.org.taverna.configuration.app.ApplicationConfiguration" />
+ <reference id="serviceRegistry" interface="uk.org.taverna.commons.services.ServiceRegistry" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context.xml b/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context.xml
new file mode 100644
index 0000000..21b43b2
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/main/resources/META-INF/spring/biomart-activity-ui-context.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="BiomartActivityIcon" class="net.sf.taverna.t2.activities.biomart.servicedescriptions.BiomartActivityIcon" />
+
+ <bean id="BiomartServiceProvider" class="net.sf.taverna.t2.activities.biomart.servicedescriptions.BiomartServiceProvider">
+ <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" />
+ </bean>
+
+ <bean id="BiomartConfigurationMenuAction" class="net.sf.taverna.t2.activities.biomart.menu.BiomartConfigurationMenuAction">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ <property name="applicationConfiguration" ref="applicationConfiguration" />
+ <property name="serviceRegistry" ref="serviceRegistry" />
+ </bean>
+
+ <bean id="BiomartActivityViewFactory" class="net.sf.taverna.t2.activities.biomart.views.BiomartActivityViewFactory">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ <property name="colourManager" ref="colourManager" />
+ <property name="applicationConfiguration" ref="applicationConfiguration" />
+ <property name="serviceRegistry" ref="serviceRegistry" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/main/resources/biomart.png
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/resources/biomart.png b/taverna-biomart-activity-ui/src/main/resources/biomart.png
new file mode 100644
index 0000000..a969908
Binary files /dev/null and b/taverna-biomart-activity-ui/src/main/resources/biomart.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java b/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
new file mode 100644
index 0000000..04ad076
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.biomart.views;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import net.sf.taverna.t2.activities.biomart.actions.BiomartActivityConfigurationAction;
+import net.sf.taverna.t2.activities.biomart.views.BiomartActivityContextualView;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+import uk.org.taverna.scufl2.api.profiles.Profile;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class TestBiomartActivityContextualView {
+ Activity activity;
+
+ @Before
+ public void setup() throws Exception {
+ activity = new Activity();
+ activity.setParent(new Profile());
+
+ Element el = getQueryElement("biomart-query.xml");
+
+ Configuration configuration = new Configuration();
+ configuration.setType(URI.create("http://ns.taverna.org.uk/2010/activity/biomart").resolve("#Config"));
+ String queryText = new XMLOutputter().outputString(new Document(el));
+ ((ObjectNode) configuration.getJson()).put("martQuery", queryText);
+
+ configuration.setConfigures(activity);
+ }
+
+ @Test @Ignore
+ public void testConfigurationAction() throws Exception {
+ BiomartActivityContextualView view = new BiomartActivityContextualView(activity, null, null, null, null, null, null, null);
+ assertNotNull("The view should provide a configuration action",view.getConfigureAction(null));
+ assertTrue("The configuration action should be an instance of BiomartActivityConfigurationAction",view.getConfigureAction(null) instanceof BiomartActivityConfigurationAction);
+ }
+
+ private Element getQueryElement(String resourceName) throws Exception {
+ InputStream inStream = TestBiomartActivityContextualView.class
+ .getResourceAsStream("/"+resourceName);
+
+ if (inStream == null)
+ throw new IOException(
+ "Unable to find resource for:"
+ + resourceName);
+ SAXBuilder builder = new SAXBuilder();
+ return builder.build(inStream).detachRootElement();
+ }
+
+ private void run() throws Exception {
+ setup();
+ BiomartActivityContextualView view = new BiomartActivityContextualView(activity, null, null, null, null, null, null, null);
+ view.setVisible(true);
+ }
+
+ public static void main(String[] args) throws Exception {
+ new TestBiomartActivityContextualView().run();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity-ui/src/test/resources/biomart-query.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/test/resources/biomart-query.xml b/taverna-biomart-activity-ui/src/test/resources/biomart-query.xml
new file mode 100644
index 0000000..0e52a23
--- /dev/null
+++ b/taverna-biomart-activity-ui/src/test/resources/biomart-query.xml
@@ -0,0 +1,24 @@
+<biomart:MartQuery
+ xmlns:biomart="http://org.embl.ebi.escience/xscufl-biomart/0.1alpha">
+ <biomart:MartService
+ location="http://www.biomart.org/biomart/martservice" />
+ <biomart:MartDataset displayName="Homo sapiens genes (NCBI36)"
+ name="hsapiens_gene_ensembl" type="TableSet" initialBatchSize="10"
+ maximumBatchSize="50000" visible="false" interface="default"
+ modified="2006-11-27 12:49:27">
+ <biomart:MartURLLocation database="ensembl_mart_41" default="1"
+ displayName="ENSEMBL 41 (SANGER)" host="www.biomart.org"
+ includeDatasets="" martUser="" name="ensembl"
+ path="/biomart/martservice" port="80" serverVirtualSchema="default"
+ virtualSchema="default" visible="1" />
+ </biomart:MartDataset>
+ <biomart:Query virtualSchemaName="default" count="0" uniqueRows="0"
+ softwareVersion="0.5" requestId="taverna">
+ <biomart:Dataset name="hsapiens_gene_ensembl">
+ <biomart:Attribute name="coding_gene_flank" />
+ <biomart:Attribute name="gene_stable_id" />
+ <biomart:Filter name="ensembl_gene_id" value="" list="true" />
+ <biomart:Filter name="upstream_flank" value="100" />
+ </biomart:Dataset>
+ </biomart:Query>
+</biomart:MartQuery>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity/pom.xml b/taverna-biomart-activity/pom.xml
new file mode 100644
index 0000000..2662e59
--- /dev/null
+++ b/taverna-biomart-activity/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <version>2.0.1-SNAPSHOT</version>
+ <artifactId>biomart-activity</artifactId>
+ <packaging>bundle</packaging>
+ <name>Taverna 2 Biomart Activity.</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.biomart</groupId>
+ <artifactId>martservice</artifactId>
+ <version>2.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>workflowmodel-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>reference-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson-databind.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>activity-test-utils</artifactId>
+ <version>${t2.activities.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-biomart-activity.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/taverna/taverna-biomart-activity.git</developerConnection>
+ <url>https://github.com/taverna/taverna-biomart-activity/</url>
+ <tag>HEAD</tag>
+ </scm>
+</project>
+
[05/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivity.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivity.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivity.java
new file mode 100644
index 0000000..e61406b
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivity.java
@@ -0,0 +1,1319 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Vector;
+
+import net.sf.taverna.t2.annotation.annotationbeans.MimeType;
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ReferenceContext;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.service.dashboard.data.ParametersTable;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyData;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyPrimaryDataSet;
+import org.biomoby.shared.MobyPrimaryDataSimple;
+import org.biomoby.shared.MobySecondaryData;
+import org.biomoby.shared.MobyService;
+import org.biomoby.shared.Utils;
+import org.jdom.Element;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+/**
+ * An Activity based on the Biomoby compliant web services. This activity
+ * implementation will contact Biomoby registry in order to find the list of
+ * extant ports at creation time.
+ *
+ * Copied from org.biomoby.client.taverna.plugin.BiomobyProcessor and
+ * org.biomoby.client.taverna.plugin.BiomobyTask and converted to a Taverna 2
+ * Activity.
+ *
+ * @author Martin Senger
+ * @author Edward Kawas
+ * @author Jose Maria Fernandez, INB
+ * @author David Withers
+ */
+public class BiomobyActivity extends
+ AbstractAsynchronousActivity<BiomobyActivityConfigurationBean> {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/biomoby/service";
+
+ private static Logger logger = Logger.getLogger(BiomobyActivity.class);
+
+ protected BiomobyActivityConfigurationBean configurationBean = new BiomobyActivityConfigurationBean();
+
+ private URL endpoint;
+
+ private Central worker = null;
+
+ private MobyService mobyService = null;
+
+ private boolean containSecondary = false;
+
+ private ParametersTable parameterTable = null;
+
+
+
+ private boolean doInit = true;
+
+ @Override
+ public void configure(BiomobyActivityConfigurationBean configurationBean)
+ throws ActivityConfigurationException {
+ this.configurationBean = configurationBean;
+ if (doInit) {
+ init();
+ generatePorts();
+ configureSecondaries();
+ doInit = false;
+ } else {
+ configureSecondaries();
+ }
+ }
+
+ @Override
+ public BiomobyActivityConfigurationBean getConfiguration() {
+ return configurationBean;
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> inputMap,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+ @SuppressWarnings("unchecked")
+ public void run() {
+ ReferenceService referenceService = callback.getContext()
+ .getReferenceService();
+
+ Map<String, T2Reference> outputMap = new HashMap<String, T2Reference>();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Service " + mobyService.getUniqueName());
+ for (Iterator it = inputMap.keySet().iterator(); it
+ .hasNext();) {
+ String key = (String) it.next();
+ try {
+ Object input = referenceService.renderIdentifier(
+ inputMap.get(key), String.class, callback
+ .getContext());
+ if (input instanceof String) {
+ logger.debug("key " + key + "has value of\n"
+ + input);
+ continue;
+ } else if (input instanceof List) {
+ List list = (List) input;
+ for (Iterator it2 = list.iterator(); it2
+ .hasNext();) {
+ logger.debug("List key " + key
+ + "has value of\n" + it2.next());
+ }
+ }
+ } catch (ReferenceServiceException e) {
+ logger.debug(
+ "Error resolving data for port " + key, e);
+ }
+ }
+ logger.debug("Printing of ports complete.");
+ }
+ // invoke services with no defined input (as per BioMOBY API)
+ if (mobyService.getPrimaryInputs().length == 0) {
+ try {
+ String methodName = configurationBean.getServiceName();
+ String serviceEndpoint = endpoint.toExternalForm();
+ String serviceInput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<moby:MOBY xmlns:moby=\"http://www.biomoby.org/moby\">"
+ + " <moby:mobyContent>"
+ + " <moby:mobyData moby:queryID=\"sip_1_\" />"
+ + " </moby:mobyContent>" + "</moby:MOBY>";
+ String[] invocations = new String[] { serviceInput };
+ // add secondaries
+ if (containSecondary) {
+ @SuppressWarnings("unused")
+ ParametersTable pt = getParameterTable();
+ Element[] parameters = null;
+ parameters = getParameterTable().toXML();
+ serviceInput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<moby:MOBY xmlns:moby=\"http://www.biomoby.org/moby\">"
+ + " <moby:mobyContent>"
+ + " <moby:mobyData moby:queryID=\"sip_1_\">";
+ XMLOutputter out = new XMLOutputter(Format
+ .getCompactFormat());
+ Format format = out.getFormat();
+ format.setOmitDeclaration(true);
+ out.setFormat(format);
+ for (int i = 0; i < parameters.length; i++) {
+ serviceInput += out.outputString(parameters[i]);
+ }
+ serviceInput += " </moby:mobyData>"
+ + " </moby:mobyContent>" + "</moby:MOBY>";
+ format = Format.getPrettyFormat();
+ format.setOmitDeclaration(false);
+ format.setIndent(" ");
+ serviceInput = new XMLOutputter(format)
+ .outputString(XMLUtilities
+ .getDOMDocument(serviceInput));
+ invocations = new String[] { serviceInput };
+ }
+
+ // execute the service that takes no Biomoby datatypes
+ // as input
+ for (int inCount = 0; inCount < invocations.length; inCount++) {
+ if (logger.isDebugEnabled())
+ logger.debug("input(" + inCount + "):\n"
+ + invocations[inCount]);
+ // execute a 'moby' service
+ invocations[inCount] = executeService(
+ serviceEndpoint, methodName,
+ invocations[inCount]);
+ if (logger.isDebugEnabled())
+ logger.debug("output(" + inCount + "):\n"
+ + invocations[inCount]);
+ }
+ String outputXML = XMLUtilities
+ .createMultipleInvokations(invocations);
+ // create the other ports
+ processOutputPorts(outputXML, outputMap,
+ referenceService, callback.getContext());
+
+ callback.receiveResult(outputMap, new int[0]);
+ return;
+ } catch (ReferenceServiceException e) {
+ callback.fail("Error accessing input/output data", e);
+ } catch (MobyException ex) {
+ // a MobyException should be already reasonably
+ // formatted
+ logger
+ .error(
+ "Error invoking biomoby service for biomoby. A MobyException caught",
+ ex);
+ callback.fail(
+ "Service failed due to problem invoking remote biomoby service.\n"
+ + ex.getMessage(), ex);
+
+ } catch (Exception ex) {
+ logger.error(
+ "Error invoking biomoby service for biomoby",
+ ex);
+ callback
+ .fail(
+ "Task failed due to problem invoking biomoby service (see details in log)",
+ ex);
+ }
+ }
+
+ {
+ // now try other named ports
+ try {
+ String inputXML = null;
+ Element root = new Element("MOBY", XMLUtilities.MOBY_NS);
+ Element content = new Element("mobyContent",
+ XMLUtilities.MOBY_NS);
+ root.addContent(content);
+ int totalMobyDatas = 0;
+ Vector mobyDatas = new Vector(); // list of mobyData
+ // element
+ for (ActivityInputPort myInput : getInputPorts()) {
+ if (myInput.getName().equalsIgnoreCase("input")) {
+ continue;
+ }
+ // the port name
+ String portName = myInput.getName();
+ // the article name
+ String articleName = "";
+ String type = portName;
+ if (portName.indexOf("(") >= 0
+ && portName.indexOf(")") > 0) {
+ articleName = portName.substring(portName
+ .indexOf("(") + 1, portName
+ .indexOf(")"));
+
+ if (articleName.indexOf("'") >= 0
+ && articleName.lastIndexOf("'") > 0)
+ articleName = articleName.substring(
+ articleName.indexOf("'") + 1,
+ articleName.lastIndexOf("'"));
+
+ type = portName.substring(0, portName
+ .indexOf("("));
+ }
+
+ // String inputType = myInput.getSyntacticType();
+ Object input = referenceService.renderIdentifier(
+ inputMap.get(portName), myInput
+ .getTranslatedElementClass(),
+ callback.getContext());
+ if (myInput.getDepth() == 0) {
+ inputXML = (String) input;
+ Element inputElement = null;
+ try {
+ inputElement = XMLUtilities.getDOMDocument(
+ inputXML).getRootElement();
+
+ } catch (MobyException e) {
+ callback
+ .fail(XMLUtilities.newline
+ + "There was an error parsing the input XML:"
+ + XMLUtilities.newline
+ + Utils.format(inputXML, 3)
+ + XMLUtilities.newline
+ + e.getLocalizedMessage());
+ return;
+ }
+ // determine whether we have a multiple
+ // invocation message
+ if (XMLUtilities
+ .isMultipleInvocationMessage(inputElement)) {
+ // multiple invocations
+ Element[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(inputElement);
+ ArrayList list = new ArrayList();
+ for (int j = 0; j < invocations.length; j++) {
+ Element[] elements = XMLUtilities
+ .getListOfCollections(invocations[j]);
+ if (elements.length == 0) {
+ // single simple
+ inputElement = XMLUtilities
+ .renameSimple(articleName,
+ type,
+ invocations[j]);
+ Element md = XMLUtilities
+ .extractMobyData(inputElement);
+ list.add(md);
+ } else {
+ // collection of simples => create
+ // multiple
+ // invocation message
+ String queryID = XMLUtilities
+ .getQueryID(invocations[j]);
+ Element[] simples = XMLUtilities
+ .getSimplesFromCollection(invocations[j]);
+ for (int k = 0; k < simples.length; k++) {
+ Element wrappedSimple = XMLUtilities
+ .createMobyDataElementWrapper(simples[k]);
+ wrappedSimple = XMLUtilities
+ .renameSimple(
+ articleName,
+ type,
+ wrappedSimple);
+ wrappedSimple = XMLUtilities
+ .setQueryID(
+ wrappedSimple,
+ queryID );
+ list
+ .add(XMLUtilities
+ .extractMobyData(wrappedSimple));
+ }
+ }
+ }
+ if (list.isEmpty())
+ continue;
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1;
+ totalMobyDatas *= list.size();
+ mobyDatas.add(list);
+ } else {
+ // single invocation
+ // is this a collection
+ Element[] elements = XMLUtilities
+ .getListOfCollections(inputElement);
+ if (elements.length == 0) {
+ // single simple
+ inputElement = XMLUtilities
+ .renameSimple(articleName,
+ type, inputElement);
+ ArrayList list = new ArrayList();
+ Element md = XMLUtilities
+ .extractMobyData(inputElement);
+ list.add(md);
+ mobyDatas.add(list);
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1;
+ } else {
+ // collection of simples => create
+ // multiple
+ // invocation message
+ String queryID = XMLUtilities
+ .getQueryID(inputElement);
+ Element[] simples = XMLUtilities
+ .getSimplesFromCollection(inputElement);
+
+ ArrayList list = new ArrayList();
+ for (int j = 0; j < simples.length; j++) {
+ Element wrappedSimple = XMLUtilities
+ .createMobyDataElementWrapper(simples[j]);
+ wrappedSimple = XMLUtilities
+ .renameSimple(articleName,
+ type, wrappedSimple);
+ wrappedSimple = XMLUtilities
+ .setQueryID(wrappedSimple,
+ queryID );
+ list
+ .add(XMLUtilities
+ .extractMobyData(wrappedSimple));
+ }
+ if (list.isEmpty())
+ continue;
+ mobyDatas.add(list);
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1 * list.size();
+ else {
+ totalMobyDatas *= list.size();
+ }
+ }
+
+ }
+ } else {
+ // we have a collection!
+ // inputThing is a list of Strings
+ List list = (List) input;
+ /*
+ * need this map in cases where simples are
+ * passed into a service that wants a
+ * collection. each simple is then added into
+ * the same collection
+ */
+ Map collectionMap = new HashMap();
+ for (Iterator it = list.iterator(); it
+ .hasNext();) {
+ Element inputElement = null;
+ String next = (String) it.next();
+ try {
+ inputElement = XMLUtilities
+ .getDOMDocument(next)
+ .getRootElement();
+
+ } catch (MobyException e) {
+ callback
+ .fail(XMLUtilities.newline
+ + "There was an error parsing the input XML:"
+ + XMLUtilities.newline
+ + Utils.format(
+ inputXML, 3)
+ + XMLUtilities.newline
+ + e
+ .getLocalizedMessage());
+ return;
+ }
+ // determine whether we have a multiple
+ // invocation message
+ if (XMLUtilities
+ .isMultipleInvocationMessage(inputElement)) {
+ // multiple invocations (update
+ // totalMobyDatas)
+ Element[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(inputElement);
+ ArrayList mdList = new ArrayList();
+ // this is here for mim messages of
+ // simples
+ Element mimCollection = null;
+ String mimQueryID = "";
+ for (int j = 0; j < invocations.length; j++) {
+ Element[] elements = XMLUtilities
+ .getListOfCollections(invocations[j]);
+ mimQueryID = XMLUtilities
+ .getQueryID(invocations[j]);
+ if (elements.length == 0) {
+ if (mimCollection == null)
+ mimCollection = new Element(
+ "Collection",
+ XMLUtilities.MOBY_NS);
+
+ Element theSimple = XMLUtilities
+ .extractMobyData(invocations[j]);
+ if (theSimple
+ .getChild("Simple") != null)
+ theSimple = theSimple
+ .getChild("Simple");
+ else if (theSimple.getChild(
+ "Simple",
+ XMLUtilities.MOBY_NS) != null)
+ theSimple = theSimple
+ .getChild(
+ "Simple",
+ XMLUtilities.MOBY_NS);
+ mimCollection
+ .addContent(theSimple
+ .detach());
+ } else {
+ // collection passed in (always
+ // 1 passed in)
+ Element collection = invocations[j];
+ collection = XMLUtilities
+ .renameCollection(
+ articleName,
+ collection);
+ collection = XMLUtilities
+ .createMobyDataElementWrapper(
+ collection,
+ XMLUtilities
+ .getQueryID(invocations[j]),
+ null);
+ mdList
+ .add(XMLUtilities
+ .extractMobyData(collection));
+ }
+ }
+ if (mimCollection != null) {
+ mimCollection = XMLUtilities
+ .createMobyDataElementWrapper(
+ mimCollection,
+ mimQueryID, null);
+ mimCollection = XMLUtilities
+ .renameCollection(
+ articleName,
+ mimCollection);
+ mimCollection = XMLUtilities
+ .createMobyDataElementWrapper(
+ mimCollection,
+ mimQueryID, null);
+ mdList
+ .add(XMLUtilities
+ .extractMobyData(mimCollection));
+ }
+
+ if (mdList.isEmpty())
+ continue;
+
+ mobyDatas.add(mdList);
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1;
+ totalMobyDatas *= mdList.size();
+ } else {
+ // single invocation
+ Element[] elements = XMLUtilities
+ .getListOfCollections(inputElement);
+ if (elements.length == 0) {
+ // simple was passed in so wrap it
+ Element collection = new Element(
+ "Collection",
+ XMLUtilities.MOBY_NS);
+ collection.addContent(XMLUtilities
+ .extractMobyData(
+ inputElement)
+ .cloneContent());
+ collection = XMLUtilities
+ .createMobyDataElementWrapper(
+ collection,
+ XMLUtilities
+ .getQueryID(inputElement),
+ null);
+ collection = XMLUtilities
+ .renameCollection(
+ articleName,
+ collection);
+ collection = XMLUtilities
+ .createMobyDataElementWrapper(
+ collection,
+ XMLUtilities
+ .getQueryID(inputElement),
+ null);
+ if (collectionMap
+ .containsKey(articleName)) {
+ // add the simple to a
+ // pre-existing
+ // collection
+ ArrayList mdList = (ArrayList) collectionMap
+ .remove(articleName);
+ mdList
+ .add(XMLUtilities
+ .extractMobyData(collection));
+ collectionMap.put(articleName,
+ mdList);
+ } else {
+ // new collection - add element
+ // and
+ // increment count
+ ArrayList mdList = new ArrayList();
+ mdList
+ .add(XMLUtilities
+ .extractMobyData(collection));
+ collectionMap.put(articleName,
+ mdList);
+ // totalMobyDatas++;
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1;
+ }
+ } else {
+ // we have a collection
+ Element collection = inputElement;
+ collection = XMLUtilities
+ .renameCollection(
+ articleName,
+ collection);
+ ArrayList mdList = new ArrayList();
+ collection = XMLUtilities
+ .createMobyDataElementWrapper(
+ collection,
+ XMLUtilities
+ .getQueryID(inputElement),
+ null);
+ mdList
+ .add(XMLUtilities
+ .extractMobyData(collection));
+ mobyDatas.add(mdList);
+ if (totalMobyDatas < 1)
+ totalMobyDatas = 1;
+
+ }
+ } // end if SIM
+ } // end iteration over inputThing list
+ Iterator collectionIterator = collectionMap
+ .keySet().iterator();
+ while (collectionIterator.hasNext()) {
+ String key = (String) collectionIterator
+ .next();
+ List theList = (List) collectionMap
+ .get(key);
+ theList = XMLUtilities.mergeCollections(
+ theList, key);
+ List unwrappedList = new ArrayList();
+ for (Iterator it = theList.iterator(); it
+ .hasNext();) {
+ Element e = (Element) it.next();
+ if (XMLUtilities.isWrapped(e))
+ unwrappedList.add(XMLUtilities
+ .extractMobyData(e));
+ else
+ unwrappedList.add(e);
+ }
+ mobyDatas.add(unwrappedList);
+ }
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Before MobyData aggregation");
+ for (Iterator itr = mobyDatas.iterator(); itr
+ .hasNext();) {
+ List eList = (List) itr.next();
+ for (int x = 0; x < eList.size(); x++) {
+ logger.debug(new XMLOutputter(Format
+ .getPrettyFormat())
+ .outputString((Element) eList
+ .get(x)));
+ }
+ }
+ logger.debug("******* End ******");
+ }
+ /*
+ * ports have been processed -> vector contains a list
+ * of all the different types of inputs with their
+ * article names set correctly. The elements are from
+ * mobyData down. Moreover, there are totalMobyData
+ * number of invocations in the output moby message
+ */
+ if (logger.isDebugEnabled()) {
+ logger.debug("TotalMobyDatas: " + totalMobyDatas);
+ }
+ Element[] mds = new Element[totalMobyDatas];
+ // initialize the mobydata blocks
+ for (int x = 0; x < mds.length; x++) {
+ mds[x] = new Element("mobyData",
+ XMLUtilities.MOBY_NS);
+ String queryID = "_";
+ // add the content
+ for (Iterator iter = mobyDatas.iterator(); iter
+ .hasNext();) {
+ ArrayList list = (ArrayList) iter.next();
+ int index = x % list.size();
+ Element next = ((Element) list.get(index));
+ logger.debug(new XMLOutputter(Format
+ .getPrettyFormat()).outputString(next));
+ // queryID += "_" +
+ // XMLUtilities.getQueryID(next);
+ queryID = XMLUtilities.getQueryID(next);
+ mds[x].addContent(next.cloneContent());
+
+ }
+ // remove the first _
+ // if (queryID != null && queryID.length() > 1)
+ // queryID = queryID.substring(1);
+ mds[x].setAttribute("queryID", queryID,
+ XMLUtilities.MOBY_NS);
+ // if secondarys exist add them here
+ if (containSecondary) {
+ @SuppressWarnings("unused")
+ ParametersTable pt = parameterTable;
+ Element[] parameters = null;
+ parameters = parameterTable.toXML();
+ for (int i = 0; i < parameters.length; i++) {
+ mds[x].addContent((parameters[i]).detach());
+ }
+ }
+ content.addContent(mds[x].detach());
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("After MobyData aggregation");
+ logger.debug(new XMLOutputter(Format
+ .getPrettyFormat()).outputString(root));
+ logger.debug("******* End ******");
+ }
+ // do the task and populate outputXML
+
+ String methodName = configurationBean.getServiceName();
+ String serviceEndpoint = endpoint.toExternalForm();
+
+ String serviceInput = new XMLOutputter(Format
+ .getPrettyFormat()).outputString(root);
+ String[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(serviceInput);
+ // logger.debug(serviceInput);
+ // going to iterate over all invocations so that
+ // messages with
+ // many mobyData blocks dont timeout.
+ logger.debug("Total invocations " + invocations.length);
+ if (invocations.length > 0)
+ logger.debug("invocation 00");
+ for (int inCount = 0; inCount < invocations.length; inCount++) {
+ if (logger.isDebugEnabled())
+ logger.info("input(" + inCount + "):\n"
+ + invocations[inCount]);
+ if (!XMLUtilities.isEmpty(invocations[inCount]))
+ invocations[inCount] = executeService(
+ serviceEndpoint, methodName,
+ invocations[inCount]);
+ if (logger.isDebugEnabled())
+ logger.info("output(" + inCount + "):\n"
+ + invocations[inCount]);
+ }
+
+ String outputXML = XMLUtilities
+ .createMultipleInvokations(invocations);
+ // create the other ports
+ processOutputPorts(outputXML, outputMap,
+ referenceService, callback.getContext());
+
+ callback.receiveResult(outputMap, new int[0]);
+
+ } catch (ReferenceServiceException e) {
+ callback.fail("Error accessing input/output data", e);
+ } catch (MobyException ex) {
+ // a MobyException should be already reasonably
+ // formatted
+ logger
+ .error(
+ "Error invoking biomoby service for biomoby. A MobyException caught",
+ ex);
+ callback.fail(
+ "Service failed due to exception invoking remote biomoby service.\n"
+ + ex.getMessage(), ex);
+
+ } catch (Exception ex) {
+ // details of other exceptions will appear only in a log
+// ex.();
+ logger.error(
+ "Error invoking biomoby service for biomoby",
+ ex);
+ callback
+ .fail(
+ "Task failed due to problem invoking biomoby service (see details in log)",
+ ex);
+ }
+
+ }
+ }
+
+ });
+
+ }
+
+ private void init() throws ActivityConfigurationException {
+ // Find the service endpoint (by calling Moby registry)
+ try {
+ if (mobyService == null) {
+ worker = new CentralImpl(configurationBean.getMobyEndpoint());
+
+ MobyService pattern = new MobyService(configurationBean
+ .getServiceName());
+ pattern.setAuthority(configurationBean.getAuthorityName());
+ pattern.setCategory("");
+ MobyService[] services = worker.findService(pattern);
+ if (services == null || services.length == 0)
+ throw new ActivityConfigurationException(
+ formatError("I cannot find the service."));
+ mobyService = services[0];
+ }
+ String serviceEndpoint = mobyService.getURL();
+ if (serviceEndpoint == null || serviceEndpoint.equals(""))
+ throw new ActivityConfigurationException(
+ formatError("Service has an empty endpoint."));
+ try {
+ endpoint = new URL(serviceEndpoint);
+ } catch (MalformedURLException e2) {
+ throw new ActivityConfigurationException(
+ formatError("Service has malformed endpoint: '"
+ + serviceEndpoint + "'."));
+ }
+
+ } catch (Exception e) {
+ if (e instanceof ActivityConfigurationException) {
+ throw (ActivityConfigurationException) e;
+ }
+ throw new ActivityConfigurationException(formatError(e.toString()));
+ }
+ // here we make sure that we have downloaded the ontology for the
+ // registry that we got this service from
+ try {
+ new GetOntologyThread(worker.getRegistryEndpoint()).start();
+ } catch (Exception e) {
+ /* don't care if an exception occurs here ... */
+ }
+
+ }
+
+ /**
+ * Use the endpoint data to create new ports and attach them to the
+ * processor.
+ */
+ private void generatePorts() {
+
+ // inputs TODO - find a better way to deal with collections
+ MobyData[] serviceInputs = this.mobyService.getPrimaryInputs();
+ int inputDepth = 0;
+ for (int x = 0; x < serviceInputs.length; x++) {
+ if (serviceInputs[x] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) serviceInputs[x];
+
+ // retrieve the simple article name
+ String simpleName = simple.getName();
+ if (simpleName.equals("")) {
+ simpleName = "_ANON_";
+ }
+ simpleName = "(" + simpleName + ")";
+
+ String portName = simple.getDataType().getName() + simpleName;
+ addInput(portName, inputDepth, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ } else {
+ // collection of items
+ inputDepth = 1;
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) serviceInputs[x];
+ String collectionName = collection.getName();
+ if (collectionName.equals(""))
+ collectionName = "MobyCollection";
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int y = 0; y < simples.length; y++) {
+ // collection port
+ String portName = simples[y].getDataType().getName()
+ + "(Collection - '" + collectionName + "')";
+ addInput(
+ portName,
+ inputDepth,
+ true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+
+ }
+ }
+ }
+ /*addInput("input", inputDepth, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);*/
+
+ MobyData[] secondaries = this.mobyService.getSecondaryInputs();
+
+ if (secondaries.length > 0) {
+ MobySecondaryData[] msd = new MobySecondaryData[secondaries.length];
+ for (int i = 0; i < secondaries.length; i++) {
+ msd[i] = (MobySecondaryData) secondaries[i];
+ }
+ containSecondary = true;
+ this.parameterTable = new org.biomoby.service.dashboard.data.ParametersTable(
+ msd);
+ updateConfigBeanSecondaries();
+ }
+
+ // outputs
+ MobyData[] serviceOutputs = this.mobyService.getPrimaryOutputs();
+ int outputDepth = 0;
+ for (int x = 0; x < serviceOutputs.length; x++) {
+ if (serviceOutputs[x] instanceof MobyPrimaryDataSimple) {
+ MobyPrimaryDataSimple simple = (MobyPrimaryDataSimple) serviceOutputs[x];
+
+ // retrieve the simple article name
+ String simpleName = simple.getName();
+ if (simpleName.equals("")) {
+ simpleName = "_ANON_";
+ }
+ simpleName = "(" + simpleName + ")";
+
+ String outputName = simple.getDataType().getName() + simpleName;
+ addOutput(outputName, outputDepth, "text/xml");
+ } else {
+ outputDepth = 1;
+ // collection of items
+ MobyPrimaryDataSet collection = (MobyPrimaryDataSet) serviceOutputs[x];
+ String collectionName = collection.getName();
+ if (collectionName.equals(""))
+ collectionName = "MobyCollection";
+ MobyPrimaryDataSimple[] simples = collection.getElements();
+ for (int y = 0; y < simples.length; y++) {
+ String outputName = simples[y].getDataType().getName()
+ + "(Collection - '" + collectionName + "')";
+ addOutput(outputName, outputDepth, "text/xml");
+
+ outputName = simples[y].getDataType().getName()
+ + "(Collection - '" + collectionName
+ + "' As Simples)";
+ addOutput(outputName, outputDepth, "text/xml");
+ }
+ }
+ }
+
+// addOutput("output", outputDepth, "text/xml");
+
+ }
+
+ /**
+ * Updates config bean secondaries for those that aren't already defined so
+ * this only records new ones, but doesn't overwrite existing ones.
+ */
+ private void updateConfigBeanSecondaries() {
+ ParametersTable table = getParameterTable();
+ int rows = table.getModel().getRowCount();
+ Map<String, String> secondaries = getConfiguration().getSecondaries();
+ for (int i = 0; i < rows; i++) {
+ String key = (String) table.getModel().getValueAt(i, 0);
+ String value = table.getModel().getValueAt(i, 1).toString();
+ if (!secondaries.containsKey(key)) {
+ secondaries.put(key, value);
+ }
+ }
+
+ }
+
+ public ParametersTable getParameterTable() {
+ return parameterTable;
+ }
+
+ public boolean containsSecondaries() {
+ return containSecondary;
+ }
+
+ public MobyService getMobyService() {
+ return mobyService;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void processOutputPorts(String outputXML, Map outputMap,
+ ReferenceService referenceService, ReferenceContext context)
+ throws MobyException, ReferenceServiceException {
+ boolean isMIM = XMLUtilities.isMultipleInvocationMessage(outputXML);
+ for (OutputPort outputPort : getOutputPorts()) {
+ String name = outputPort.getName();
+ if (!name.equalsIgnoreCase("output")) {
+ if (outputPort.getDepth() == 1) {
+ // collection - list of strings
+ String articleName = "";
+ if (name.indexOf("MobyCollection") > 0) {
+ // un-named collection -> ignore it as it is illegal
+ // in the api
+ // TODO could throw exception
+
+ List innerList = new ArrayList();
+ outputMap.put(name, referenceService
+ .register(innerList, outputPort.getDepth(),
+ true, context));
+ continue;
+ } else {
+ articleName = name.substring(name.indexOf("'") + 1,
+ name.lastIndexOf("'"));
+ if (name.indexOf("' As Simples)") > 0) {
+ // list of simples wanted
+ if (isMIM) {
+ String[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(outputXML);
+
+ List innerList = new ArrayList();
+ Element serviceNotesElement = XMLUtilities
+ .getServiceNotesAsElement(outputXML);
+ for (int i = 0; i < invocations.length; i++) {
+ try {
+ String collection = XMLUtilities
+ .getWrappedCollection(
+ articleName,
+ invocations[i]);
+ String[] simples = XMLUtilities
+ .getSimplesFromCollection(
+ articleName, collection);
+ for (int j = 0; j < simples.length; j++) {
+ innerList
+ .add(XMLUtilities
+ .createMobyDataElementWrapper(
+ simples[j],
+ XMLUtilities
+ .getQueryID(collection)
+ /*
+ * + "_+_s"
+ * +
+ * qCounter
+ * ++
+ */,
+ serviceNotesElement));
+ }
+ } catch (MobyException e) {
+ // collection didnt exist, so put an
+ // empty
+ // mobyData
+ // TODO keep the original wrapper
+ /*
+ * String qID =
+ * XMLUtilities.getQueryID(invocations
+ * [i]); Element empty =
+ * XMLUtilities.createMobyDataWrapper
+ * (qID,
+ * XMLUtilities.getServiceNotesAsElement
+ * (outputXML)); XMLOutputter output =
+ * new XMLOutputter(Format
+ * .getPrettyFormat());
+ * innerList.add(output
+ * .outputString(empty));
+ */
+ }
+ }
+ outputMap.put(name, referenceService.register(
+ innerList, outputPort.getDepth(), true,
+ context));
+ } else {
+ // process the single invocation and put string
+ // into
+ // a
+ // list
+ try {
+
+ List innerList = new ArrayList();
+ String collection = XMLUtilities
+ .getWrappedCollection(articleName,
+ outputXML);
+
+ String[] simples = XMLUtilities
+ .getSimplesFromCollection(
+ articleName, collection);
+ Element serviceNotesElement = XMLUtilities
+ .getServiceNotesAsElement(outputXML);
+ for (int i = 0; i < simples.length; i++) {
+ innerList
+ .add(XMLUtilities
+ .createMobyDataElementWrapper(
+ simples[i],
+ XMLUtilities
+ .getQueryID(collection),
+ serviceNotesElement));
+ }
+
+ outputMap
+ .put(
+ name,
+ referenceService
+ .register(
+ innerList,
+ outputPort
+ .getDepth(),
+ true,
+ context));
+ } catch (MobyException e) {
+ List innerList = new ArrayList();
+ outputMap
+ .put(
+ name,
+ referenceService
+ .register(
+ innerList,
+ outputPort
+ .getDepth(),
+ true,
+ context));
+ }
+ }
+ } else {
+ if (isMIM) {
+ // process each invocation and then merge them
+ // into
+ // a
+ // single string
+ String[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(outputXML);
+
+ List innerList = new ArrayList();
+ for (int i = 0; i < invocations.length; i++) {
+ try {
+ String collection = XMLUtilities
+ .getWrappedCollection(
+ articleName,
+ invocations[i]);
+ innerList.add(collection);
+ } catch (MobyException e) {
+
+ }
+ }
+
+ outputMap.put(name, referenceService.register(
+ innerList, outputPort.getDepth(), true,
+ context));
+ } else {
+
+ try {
+
+ List innerList = new ArrayList();
+ String collection = XMLUtilities
+ .getWrappedCollection(articleName,
+ outputXML);
+ innerList.add(collection);
+ outputMap
+ .put(
+ name,
+ referenceService
+ .register(
+ innerList,
+ outputPort
+ .getDepth(),
+ true,
+ context));
+ } catch (MobyException e) {
+ List innerList = new ArrayList();
+ outputMap
+ .put(
+ name,
+ referenceService
+ .register(
+ innerList,
+ outputPort
+ .getDepth(),
+ true,
+ context));
+ }
+ }
+ }
+ }
+ } else {
+ // simple - single string
+ if (name.indexOf("_ANON_") > 0) {
+ // un-named simple -> ignore it as it is illegal in the
+ // api
+ // TODO could throw exception
+
+ String empty = new XMLOutputter()
+ .outputString(XMLUtilities
+ .createMobyDataWrapper(
+ XMLUtilities
+ .getQueryID(outputXML),
+ XMLUtilities
+ .getServiceNotesAsElement(outputXML)));
+ List innerList = new ArrayList();
+ innerList.add(empty);
+ outputMap.put(name, referenceService.register(empty,
+ outputPort.getDepth(), true, context));
+ // FIXME outputMap.put(name, new
+ // DataThing((Object)null));
+ continue;
+ } else {
+ // TODO what if you make mim messages a single string
+ // and then simples always output 'text/xml'?
+ String articleName = name.substring(
+ name.indexOf("(") + 1, name.indexOf(")"));
+ if (isMIM) {
+
+ String[] invocations = XMLUtilities
+ .getSingleInvokationsFromMultipleInvokations(outputXML);
+
+ ArrayList innerList = new ArrayList();
+
+ for (int i = 0; i < invocations.length; i++) {
+ try {
+ String simple = XMLUtilities
+ .getWrappedSimple(articleName,
+ invocations[i]);
+ innerList.add(simple);
+ } catch (MobyException e) {
+ // simple didnt exist, so put an empty
+ // mobyData
+ // TODO keep the original wrapper
+ String qID = XMLUtilities
+ .getQueryID(invocations[i]);
+
+ Element empty = XMLUtilities
+ .createMobyDataWrapper(
+ qID,
+ XMLUtilities
+ .getServiceNotesAsElement(outputXML));
+ XMLOutputter output = new XMLOutputter(
+ Format.getPrettyFormat());
+ // invocations[i] =
+ // output.outputString(empty);
+ innerList.add(output.outputString(empty));
+ // FIXME outputMap.put(name, new
+ // DataThing(""));
+ }
+ }
+ String[] s = new String[innerList.size()];
+ s = (String[]) innerList.toArray(s);
+ try {
+ outputMap.put(name, referenceService.register(
+ XMLUtilities
+ .createMultipleInvokations(s),
+ outputPort.getDepth(), true, context));
+ } catch (MobyException e) {
+ logger
+ .error("Error creating output for service: "
+ + "."
+ + System
+ .getProperty("line.separator")
+ + e.getMessage());
+ outputMap.put(name, referenceService.register(
+ "", outputPort.getDepth(), true,
+ context));
+ }
+ } else {
+ // process the single invocation and put into a
+ // string
+ try {
+ String simple = XMLUtilities.getWrappedSimple(
+ articleName, outputXML);
+ ArrayList innerList = new ArrayList();
+ innerList.add(simple);
+ outputMap.put(name, referenceService.register(
+ simple, outputPort.getDepth(), true,
+ context));
+ } catch (MobyException e) {
+ // simple didnt exist, so put an empty mobyData
+ // TODO keep the original wrapper
+ String qID = XMLUtilities.getQueryID(outputXML);
+ Element empty = XMLUtilities
+ .createMobyDataWrapper(
+ qID,
+ XMLUtilities
+ .getServiceNotesAsElement(outputXML));
+ XMLOutputter output = new XMLOutputter(Format
+ .getPrettyFormat());
+ ArrayList innerList = new ArrayList();
+ innerList.add(output.outputString(empty));
+ outputMap.put(name, referenceService.register(
+ output.outputString(empty), outputPort
+ .getDepth(), true, context));
+ // FIXME outputMap.put(name, new DataThing(""));
+
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ protected String formatError(String msg) {
+ // Removed references to the authority, some errors
+ // were causing it to be null which in turn threw
+ // a NPE from here, breaking Taverna's error handlers
+ return ("Problems with service '" + configurationBean.getServiceName()
+ + "' provided by authority '"
+ + configurationBean.getAuthorityName()
+ + "'\nfrom Moby registry at "
+ + configurationBean.getMobyEndpoint() + ":\n\n" + msg);
+ }
+
+ protected ActivityInputPort getInputPort(String name) {
+ for (ActivityInputPort port : getInputPorts()) {
+ if (port.getName().equals(name)) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ protected OutputPort getOutputPort(String name) {
+ for (OutputPort port : getOutputPorts()) {
+ if (port.getName().equals(name)) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ protected void addOutput(String portName, int portDepth, String type) {
+ OutputPort port = edits.createActivityOutputPort(
+ portName, portDepth, portDepth);
+ MimeType mimeType = new MimeType();
+ mimeType.setText(type);
+ try {
+ edits.getAddAnnotationChainEdit(port, mimeType)
+ .doEdit();
+ } catch (EditException e) {
+ logger.debug("Error adding MimeType annotation to port", e);
+ }
+ outputPorts.add(port);
+ }
+
+ private void configureSecondaries() {
+ if (configurationBean.getSecondaries().size() > 0
+ && containsSecondaries()) {
+ MobyData[] datas = getMobyService().getSecondaryInputs();
+ for (Entry<String, String> entry : configurationBean
+ .getSecondaries().entrySet()) {
+ String name = entry.getKey();
+ String value = entry.getValue();
+ for (int i = 0; i < datas.length; i++) {
+ if (datas[i].getName().equals(name)) {
+ ((MobySecondaryData) datas[i]).setDefaultValue(value);
+ break;
+ }
+ }
+ }
+ MobySecondaryData[] msd = new MobySecondaryData[datas.length];
+ for (int i = 0; i < datas.length; i++) {
+ msd[i] = (MobySecondaryData) datas[i];
+ }
+ setParameterTable(new ParametersTable(msd));
+ }
+ }
+
+ private void setParameterTable(ParametersTable table) {
+ parameterTable = table;
+ }
+
+ private String executeService(String url, String serviceName, String xml)
+ throws MobyException {
+ // here we get the wsdl before calling the service, as the biomoby api assumes ...
+ try {
+ new RetrieveWsdlThread(worker, mobyService).start();
+ } catch (Exception e) {
+ /* don't care if an exception occurs here ... */
+ logger.info("Problem getting the biomoby wsdl for " + mobyService.getUniqueName() + ".\n" + e.getLocalizedMessage());
+ }
+ String serviceCategory = mobyService.getCategory();
+ if (serviceCategory.equalsIgnoreCase(MobyService.CATEGORY_MOBY)) {
+ return ExecuteMobyService.executeMobyService(url, serviceName, xml);
+ } else if (serviceCategory.equalsIgnoreCase("cgi")) {
+ return ExecuteCgiService.executeCgiService(url, xml);
+ } else if (serviceCategory.equalsIgnoreCase(MobyService.CATEGORY_MOBY_ASYNC)) {
+ return ExecuteAsyncMobyService.executeMobyAsyncService(url, serviceName, xml);
+ } else if (serviceCategory.equalsIgnoreCase("cgi-async")) {
+ return ExecuteAsyncCgiService.executeMobyCgiAsyncService(url, serviceName, xml);
+ }
+ // TODO should we throw an exception here?
+ return "";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityConfigurationBean.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityConfigurationBean.java
new file mode 100644
index 0000000..03abb6e
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityConfigurationBean.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A configuration bean specific to the Biomoby activity.
+ *
+ * @author David Withers
+ */
+@ConfigurationBean(uri = BiomobyActivity.URI + "#Config")
+public class BiomobyActivityConfigurationBean {
+
+ private String mobyEndpoint="";
+
+ private String serviceName="";
+
+ private String authorityName="";
+
+ @Deprecated
+ private String category = "";
+ @Deprecated
+ private String serviceType = "";
+
+ private Map<String,String> secondaries=new HashMap<String,String>();
+
+ /**
+ * Returns the mobyEndpoint.
+ *
+ * @return the mobyEndpoint
+ */
+ public String getMobyEndpoint() {
+ return mobyEndpoint;
+ }
+
+ /**
+ * Sets the mobyEndpoint.
+ *
+ * @param mobyEndpoint the new mobyEndpoint
+ */
+ @ConfigurationProperty(name = "mobyEndpoint", label = "Moby Endpoint")
+ public void setMobyEndpoint(String mobyEndpoint) {
+ this.mobyEndpoint = mobyEndpoint;
+ }
+
+ /**
+ * Returns the serviceName.
+ *
+ * @return the serviceName
+ */
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ /**
+ * Sets the serviceName.
+ *
+ * @param serviceName the new serviceName
+ */
+ @ConfigurationProperty(name = "serviceName", label = "Service Name")
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ /**
+ * Returns the authorityName.
+ *
+ * @return the authorityName
+ */
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ /**
+ * Sets the authorityName.
+ *
+ * @param authorityName the new authorityName
+ */
+ @ConfigurationProperty(name = "authorityName", label = "Authority Name")
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+ /**
+ * Returns the secondaries
+ *
+ * @return secondaries as a HashMap
+ */
+ public Map<String,String> getSecondaries() {
+ return secondaries;
+ }
+
+ /**
+ *
+ * @param secondaries
+ */
+ public void setSecondaries(Map<String,String> secondaries) {
+ this.secondaries=secondaries;
+ }
+
+ @ConfigurationProperty(name = "secondaries", label = "Secondaries", required=false)
+ public void setSecondaries(Set<Secondary> secondaries) {
+ Map<String,String> secondariesMap = new HashMap<String,String>();
+ for (Secondary secondary : secondaries) {
+ secondariesMap.put(secondary.getKey(), secondary.getValue());
+ }
+ this.secondaries=secondariesMap;
+ }
+
+ @ConfigurationBean(uri = BiomobyActivity.URI + "#Secondary")
+ public static class Secondary {
+ private String key, value;
+
+ public String getKey() {
+ return key;
+ }
+
+ @ConfigurationProperty(name = "key", label = "Key")
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @ConfigurationProperty(name = "value", label = "Value")
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityFactory.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityFactory.java
new file mode 100644
index 0000000..9a7bdf0
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+
+/**
+ * An {@link ActivityFactory} for creating <code>BiomobyActivity</code>.
+ *
+ * @author David Withers
+ */
+public class BiomobyActivityFactory implements ActivityFactory {
+
+ @Override
+ public BiomobyActivity createActivity() {
+ return new BiomobyActivity();
+ }
+
+ @Override
+ public URI getActivityURI() {
+ return URI.create(BiomobyActivity.URI);
+ }
+
+ @Override
+ public Object createActivityConfiguration() {
+ return new BiomobyActivityConfigurationBean();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthChecker.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthChecker.java
new file mode 100644
index 0000000..aec3d1a
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyActivityHealthChecker.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.util.List;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.visit.VisitReport;
+
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
+
+/**
+ * A health checker for the Biomoby activity.
+ *
+ * @author David Withers
+ */
+public class BiomobyActivityHealthChecker extends RemoteHealthChecker {
+
+ public boolean canVisit(Object subject) {
+ if (subject == null) {
+ return false;
+ }
+ if (subject instanceof BiomobyActivity) {
+ return true;
+ }
+ if (subject instanceof DisabledActivity) {
+ return (((DisabledActivity) subject).getActivity() instanceof BiomobyActivity);
+ }
+ return false;
+ }
+
+ public VisitReport visit(Object o, List<Object> ancestors) {
+ Activity activity = (Activity) o;
+ BiomobyActivityConfigurationBean configuration = null;
+ if (activity instanceof BiomobyActivity) {
+ configuration = (BiomobyActivityConfigurationBean) activity.getConfiguration();
+ } else if (activity instanceof DisabledActivity) {
+ configuration = (BiomobyActivityConfigurationBean) ((DisabledActivity) activity).getActivityConfiguration();
+ }
+ return contactEndpoint(activity, configuration.getMobyEndpoint());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyCache.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyCache.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyCache.java
new file mode 100644
index 0000000..288e654
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyCache.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralDigestCachedImpl;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyNamespace;
+
+/**
+ * A utility class that handles triggering JMoby to cache for a given {@link Registry} for a given registry
+ *
+ * @author Stuart Owen
+ * @author Eddie Kawas
+ */
+
+public class BiomobyCache {
+
+ private static Logger logger = Logger.getLogger(BiomobyCache.class);
+
+ private static Map<String,Object> cached = new HashMap<String, Object>();
+
+ /**
+ * If necessary caches the Ontology and namespace information.
+ * This call immediately returns if the cache has been previously called for this endpoint
+ *
+ * @param reg - the Registry instance
+ *
+ */
+ public static synchronized void cacheForRegistry(Registry reg) {
+ if (cached.get(reg.getEndpoint()) == null) {
+ logger.info("Caching started for Biomoby registry"
+ + reg.getEndpoint());
+
+ Central c;
+ try {
+ c = CentralImpl.getDefaultCentral(reg);
+ if (c instanceof CentralDigestCachedImpl)
+ ((CentralDigestCachedImpl) c)
+ .updateCache(CentralDigestCachedImpl.CACHE_PART_DATATYPES);
+ MobyDataType.getDataType("Object", reg);
+ MobyNamespace.getNamespace("foo", reg);
+
+ cached.put(reg.getEndpoint(), new Boolean(true));
+ logger.info("Caching complete for Biomoby registry"
+ + reg.getEndpoint());
+
+ } catch (MobyException e) {
+ logger.error("Error whilst caching for Biomoby registry",e);
+ }
+
+ }
+ }
+
+ /**
+ * If necessary caches the Ontology and namespace information.
+ * This call immediately returns if the cache has been previously called for this endpoint url.
+ *
+ * @param endpointUrl - the Registry endpoint Url
+ *
+ */
+ public static synchronized void cacheForRegistryEndpoint(String endpointUrl) {
+ Registry registry = new Registry(endpointUrl, endpointUrl,
+ "http://domain.com/MOBY/Central");
+ cacheForRegistry(registry);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivity.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivity.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivity.java
new file mode 100644
index 0000000..41e8c4f
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivity.java
@@ -0,0 +1,545 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sf.taverna.t2.annotation.annotationbeans.MimeType;
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.MobyRelationship;
+import org.biomoby.shared.NoSuccessException;
+import org.biomoby.shared.data.MobyDataBoolean;
+import org.biomoby.shared.data.MobyDataComposite;
+import org.biomoby.shared.data.MobyDataDateTime;
+import org.biomoby.shared.data.MobyDataFloat;
+import org.biomoby.shared.data.MobyDataInstance;
+import org.biomoby.shared.data.MobyDataInt;
+import org.biomoby.shared.data.MobyDataString;
+import org.jdom.Element;
+
+/**
+ * An Activity providing Biomoby Object functionality.
+ *
+ * Copied from org.biomoby.client.taverna.plugin.BiomobyObjectProcessor and
+ * org.biomoby.client.taverna.plugin.BiomobyObjectTask and converted to a Taverna 2
+ * Activity.
+ *
+ * @author Edward Kawas
+ * @author David Withers
+ */
+public class BiomobyObjectActivity extends AbstractAsynchronousActivity<BiomobyObjectActivityConfigurationBean> {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/biomoby/object";
+
+ private static Logger logger = Logger.getLogger(BiomobyObjectActivity.class);
+
+ private BiomobyObjectActivityConfigurationBean configurationBean = new BiomobyObjectActivityConfigurationBean();
+
+ private Central worker = null;
+
+ private MobyDataType mobyObject = null;
+
+ @Override
+ public void configure(BiomobyObjectActivityConfigurationBean configurationBean) throws ActivityConfigurationException {
+ this.configurationBean = configurationBean;
+ init();
+ generatePorts();
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ public void run() {
+ ReferenceService referenceService = callback.getContext().getReferenceService();
+
+ Map<String, T2Reference> outputMap = new HashMap<String, T2Reference>();
+
+ // initialize the namespace and id fields
+ String namespace = "";
+ String id = "";
+ String article = "";
+ boolean isPrimitiveType = getInputPort("value")!=null;
+ String objectName = configurationBean.getServiceName();
+ // would like to use the MobyObjectClass to generate a skeleton
+
+ String registryEndpoint = worker.getRegistryEndpoint();
+ Registry mRegistry = new Registry(registryEndpoint,registryEndpoint,"http://domain.com/MOBY/Central");
+
+ BiomobyCache.cacheForRegistry(mRegistry);
+
+ if (isPrimitiveType) {
+ try {
+
+ T2Reference inputId;
+ try {
+ inputId = data.get("namespace");
+ namespace = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ try {
+ inputId = data.get("id");
+ id = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ try {
+ inputId = data.get("article name");
+ article = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ inputId = data.get("value");
+ String value = null;
+ try {
+ value = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ }
+ catch(NullPointerException e) {
+ //means the value hasn't been set and is handled below
+ }
+
+ if (objectName.equals("String")) {
+ if (value == null) {
+ value = "";
+ }
+ MobyDataString d = new MobyDataString(value,mRegistry);
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ } else if (objectName.equals("Float")) {
+ if (value == null || value.trim().equals("")) {
+ MobyDataComposite d = new MobyDataComposite(
+ MobyDataType.getDataType("Float", mRegistry));
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ } else {
+ MobyDataFloat d = new MobyDataFloat(value,mRegistry);
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ }
+ } else if (objectName.equals("Integer")) {
+
+ try {
+ int val = 0;
+ val = Integer.parseInt(value);
+ MobyDataInt d = new MobyDataInt(val,mRegistry);
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ } catch (Exception e) {
+ MobyDataComposite d = new MobyDataComposite(
+ MobyDataType.getDataType("Integer", mRegistry));
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ }
+ }else if (objectName.equals("Boolean")) {
+ if (value == null || value.trim().equals("")) {
+ MobyDataComposite d = new MobyDataComposite(MobyDataType.getDataType("Boolean", mRegistry));
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ } else {
+ MobyDataBoolean d = new MobyDataBoolean(value,mRegistry);
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ }
+ } else if (objectName.equals("DateTime")) {
+ if (value == null || value.trim().equals("")) {
+ MobyDataComposite d = new MobyDataComposite(MobyDataType.getDataType("DateTime", mRegistry));
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ } else {
+ MobyDataDateTime d = new MobyDataDateTime("", value,mRegistry);
+ d.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ d.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ d.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+ outputMap.put("mobyData", referenceService.register(XMLUtilities.createMobyDataElementWrapper(
+ "<Simple articleName=\""+article+"\">" + d.toXML() +"</Simple>" ), 0, true, callback.getContext()));
+ }
+ }
+ callback.receiveResult(outputMap, new int[0]);
+ } catch (Exception ex) {
+ // details of other exceptions will appear only in a log
+ logger.error("Error creating biomoby object for biomoby", ex);
+ callback.fail("Service failed due to problem creating biomoby object (see details in log)", ex);
+ }
+ } else {
+ // Situation where simples are feeding into this non primitive type
+ try {
+ T2Reference inputId;
+ try {
+ inputId = data.get("namespace");
+ namespace = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ try {
+ inputId = data.get("id");
+ id = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ try {
+ inputId = data.get("article name");
+ article = (String) referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+ } catch (Exception e) {
+ }
+
+ //Element mobyObjectElement = mo.createObject(objectName,namespace, id, article);
+
+ MobyDataComposite composite = new MobyDataComposite(MobyDataType.getDataType(objectName, mRegistry));
+ composite.setId(id);
+ MobyNamespace mNamespace = MobyNamespace.getNamespace(namespace,mRegistry);
+ if (mNamespace != null)
+ composite.setPrimaryNamespace(MobyNamespace.getNamespace(namespace,mRegistry));
+ composite.setXmlMode(MobyDataInstance.SERVICE_XML_MODE);
+
+ // Element mobyObjectElement = XMLUtilities.getDOMDocument(XMLUtilities.createMobyDataElementWrapper( "<Simple articleName=\""+article+"\">" + composite.toXML() +"</Simple>" )).detachRootElement();
+ Element mobyObjectElement = XMLUtilities.getDOMDocument(( composite.toXML() )).detachRootElement();
+
+ // using the inputs, iterate through and fill in data
+ for (ActivityInputPort inputPort : getInputPorts()) {
+ String portName = inputPort.getName();
+ if (!(portName.equalsIgnoreCase("namespace")
+ || portName.equalsIgnoreCase("id") || portName
+ .equalsIgnoreCase("article name"))) {
+ String type = portName.substring(0, portName
+ .indexOf("("));
+ String articleName = portName.substring(
+ type.length() + 1, portName.length() - 1);
+ inputId = null;
+ try {
+ inputId = data.get(portName);
+ } catch (Exception e) {
+
+ }
+ if (inputId != null) {
+ String value = (String) referenceService.renderIdentifier(inputId, inputPort.getTranslatedElementClass(), callback.getContext());
+ Element valueElement = (XMLUtilities.getDOMDocument(value)).getRootElement();
+ if (valueElement.getChild("mobyContent",XMLUtilities.MOBY_NS) != null) {
+ valueElement = valueElement.getChild("mobyContent",XMLUtilities.MOBY_NS);
+ } else {
+ valueElement = valueElement.getChild("mobyContent");
+ }
+ if (valueElement.getChild("mobyData",XMLUtilities.MOBY_NS) != null ) {
+ valueElement = valueElement.getChild("mobyData",XMLUtilities.MOBY_NS);
+ } else {
+ valueElement = valueElement.getChild("mobyData");
+ }
+ if (valueElement.getChild("Simple",XMLUtilities.MOBY_NS) != null ) {
+ valueElement = valueElement.getChild("Simple",XMLUtilities.MOBY_NS);
+ } else {
+ valueElement = valueElement.getChild("Simple");
+ }
+ if (valueElement.getChild(type,XMLUtilities.MOBY_NS) != null ) {
+ valueElement = valueElement.getChild(type,XMLUtilities.MOBY_NS);
+ } else {
+ valueElement = valueElement.getChild(type);
+ }
+ // Element _child = mo.getObject(mobyObjectElement,type, articleName);
+
+ valueElement.removeAttribute("articleName");
+ valueElement.removeAttribute("articleName", XMLUtilities.MOBY_NS);
+ valueElement.setAttribute("articleName", articleName, XMLUtilities.MOBY_NS);
+// Element _newChild = mo.createObject(type, _ns, _id,
+// articleName);
+// _newChild.setText(valueElement
+// .getText());
+// _newChild.addContent(_child.cloneContent());
+ // import and replace the node
+ // mobyObjectElement.removeContent(_child);
+ mobyObjectElement.addContent(valueElement.detach());
+ }
+ }
+ }
+ Element simple = new Element("Simple", XMLUtilities.MOBY_NS);
+ simple.setAttribute("articleName", article, XMLUtilities.MOBY_NS);
+ simple.addContent(mobyObjectElement);
+
+ org.jdom.output.XMLOutputter outputter = new org.jdom.output.XMLOutputter(org.jdom.output.Format.getPrettyFormat());
+ String mobyDataString = outputter.outputString(XMLUtilities.createMobyDataElementWrapper(simple));
+ outputMap.put("mobyData", referenceService.register(mobyDataString, 0, true, callback.getContext()));
+
+ callback.receiveResult(outputMap, new int[0]);
+ } catch (Exception ex) {
+ // details of other exceptions will appear only in a log
+ logger.error("Error creating biomoby object for biomoby", ex);
+ callback.fail("Service failed due to problem creating biomoby object (see details in log)", ex);
+ }
+ }
+ }
+ });
+
+ }
+
+ @Override
+ public BiomobyObjectActivityConfigurationBean getConfiguration() {
+ return configurationBean;
+ }
+
+ private void init() throws ActivityConfigurationException {
+ // Find the service endpoint (by calling Moby registry)
+ try {
+ if (mobyObject == null) {
+ worker = new CentralImpl(configurationBean.getMobyEndpoint());
+ mobyObject = worker.getDataType(configurationBean.getServiceName());
+ }
+
+ } catch (Exception e) {
+ if (e instanceof ActivityConfigurationException) {
+ throw (ActivityConfigurationException) e;
+ }
+ throw new ActivityConfigurationException(formatError(e.toString()));
+ }
+ // here we make sure that we have downloaded the ontology for the
+ // registry that we got this service from
+ try {
+ new GetOntologyThread(worker.getRegistryEndpoint()).start();
+ } catch (Exception e) {
+ /* don't care if an exception occurs here ... */
+ }
+ }
+
+ private void generatePorts() {
+ removeInputs();
+ removeOutputs();
+
+ //inputs
+ addInput("namespace", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+
+ addInput("id", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+
+ addInput("article name", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+
+ try {
+ String serviceName = configurationBean.getServiceName();
+ MobyDataType datatype = worker.getDataType(serviceName);
+ MobyRelationship[] relations = datatype.getChildren();
+ processRelationships(relations);
+ String parent = "Object";
+ try {
+ parent = datatype.getParentNames()[0];
+ if (parent.indexOf(":") > 0) {
+ parent = parent.substring(parent.lastIndexOf(":") + 1);
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // parent is then by default object
+ }
+ if (parent.equalsIgnoreCase("String")
+ || parent.equalsIgnoreCase("Integer")
+ || parent.equalsIgnoreCase("float")
+ || parent.equalsIgnoreCase("DateTime")
+ || parent.equalsIgnoreCase("Boolean")
+ || serviceName.equalsIgnoreCase("String")
+ || serviceName.equalsIgnoreCase("Boolean")
+ || serviceName.equalsIgnoreCase("Integer")
+ || serviceName.equalsIgnoreCase("float")
+ || serviceName.equalsIgnoreCase("DateTime")) {
+ addInput("value", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ } else {
+ if (!parent.equalsIgnoreCase("Object"))
+ extractParentContainerRelationships(parent);
+ }
+ } catch (MobyException e) {
+ } catch (NoSuccessException e) {
+ }
+
+ //outputs
+ addOutput("mobyData", 0, "text/xml");
+ }
+
+ private void extractParentContainerRelationships(String string) {
+ try {
+ MobyDataType datatype = worker.getDataType(string);
+ // need to propagate the isa up to Object to get all of the has/hasa
+ MobyRelationship[] relations = datatype.getChildren();
+ processRelationships(relations);
+ String parent = "Object";
+ try {
+ parent = datatype.getParentNames()[0];
+ if (parent.indexOf(":") > 0) {
+ parent = parent.substring(parent.lastIndexOf(":") + 1);
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // parent is then by default object
+ }
+ String serviceName = configurationBean.getServiceName();
+ if (parent.equalsIgnoreCase("String")
+ || parent.equalsIgnoreCase("Integer")
+ || parent.equalsIgnoreCase("float")
+ || serviceName.equalsIgnoreCase("String")
+ || parent.equalsIgnoreCase("Boolean")
+ || serviceName.equalsIgnoreCase("Boolean")
+ || serviceName.equalsIgnoreCase("Integer")
+ || serviceName.equalsIgnoreCase("float")) {
+ addInput("value", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ } else {
+ if (!parent.equalsIgnoreCase("Object"))
+ extractParentContainerRelationships(parent);
+ }
+ } catch (MobyException e) {
+ } catch (NoSuccessException e) {
+ }
+ }
+
+ private void processRelationships(MobyRelationship[] relations) {
+ for (int x = 0; x < relations.length; x++) {
+ MobyRelationship relationship = relations[x];
+
+ // strip urn:lsid:...
+ String name = relationship.getDataTypeName();
+ if (name.indexOf(":") > 0) {
+ name = name.substring(name.lastIndexOf(":") + 1);
+ }
+ // port name == DataType(articleName)
+ name = name + "(" + relationship.getName() + ")";
+ switch (relationship.getRelationshipType()) {
+ case (Central.iHAS): {
+ // TODO - not really supported
+ addInput(name, 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ break;
+ }
+ case (Central.iHASA): {
+ addInput(name, 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+
+
+ protected String formatError(String msg) {
+ // Removed references to the authority, some errors
+ // were causing it to be null which in turn threw
+ // a NPE from here, breaking Taverna's error handlers
+ return ("Problems with service '" + configurationBean.getServiceName()
+ + "' provided by authority '"
+ + configurationBean.getAuthorityName()
+ + "'\nfrom Moby registry at "
+ + configurationBean.getMobyEndpoint() + ":\n\n" + msg);
+ }
+
+ protected ActivityInputPort getInputPort(String name) {
+ for (ActivityInputPort port : getInputPorts()) {
+ if (port.getName().equals(name)) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ protected OutputPort getOutputPort(String name) {
+ for (OutputPort port : getOutputPorts()) {
+ if (port.getName().equals(name)) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ protected void addOutput(String portName, int portDepth, String type) {
+ OutputPort port = edits.createActivityOutputPort(
+ portName, portDepth, portDepth);
+ MimeType mimeType = new MimeType();
+ mimeType.setText(type);
+ try {
+ edits.getAddAnnotationChainEdit(port, mimeType).doEdit();
+ } catch (EditException e) {
+ logger.debug("Error adding MimeType annotation to port", e);
+ }
+ outputPorts.add(port);
+ }
+
+ public Central getCentral() {
+ if (worker != null)
+ return worker;
+ else
+ try {
+ return new CentralImpl(getConfiguration().getMobyEndpoint());
+ } catch (MobyException e) {
+ return null;
+ }
+ }
+
+ public MobyDataType getMobyObject() {
+ return mobyObject;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityConfigurationBean.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityConfigurationBean.java
new file mode 100644
index 0000000..ab26b32
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityConfigurationBean.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A configuration bean specific to the Biomoby Object activity.
+ *
+ * @author David Withers
+ */
+@ConfigurationBean(uri = BiomobyObjectActivity.URI + "#Config")
+public class BiomobyObjectActivityConfigurationBean {
+
+ private String mobyEndpoint="";
+
+ private String serviceName="";
+
+ private String authorityName="";
+
+ /**
+ * Returns the mobyEndpoint.
+ *
+ * @return the mobyEndpoint
+ */
+ public String getMobyEndpoint() {
+ return mobyEndpoint;
+ }
+
+ /**
+ * Sets the mobyEndpoint.
+ *
+ * @param mobyEndpoint the new mobyEndpoint
+ */
+ @ConfigurationProperty(name = "mobyEndpoint", label = "Moby Endpoint", description = "")
+ public void setMobyEndpoint(String mobyEndpoint) {
+ this.mobyEndpoint = mobyEndpoint;
+ }
+
+ /**
+ * Returns the serviceName.
+ *
+ * @return the serviceName
+ */
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ /**
+ * Sets the serviceName.
+ *
+ * @param serviceName the new serviceName
+ */
+ @ConfigurationProperty(name = "serviceName", label = "Service Name", description = "")
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ /**
+ * Returns the authorityName.
+ *
+ * @return the authorityName
+ */
+ public String getAuthorityName() {
+ return authorityName;
+ }
+
+ /**
+ * Sets the authorityName.
+ *
+ * @param authorityName the new authorityName
+ */
+ @ConfigurationProperty(name = "authorityName", label = "Authority Name", description = "")
+ public void setAuthorityName(String authorityName) {
+ this.authorityName = authorityName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityFactory.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityFactory.java
new file mode 100644
index 0000000..955b808
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+
+/**
+ * An {@link ActivityFactory} for creating <code>BiomobyObjectActivity</code>.
+ *
+ * @author David Withers
+ */
+public class BiomobyObjectActivityFactory implements ActivityFactory {
+
+ @Override
+ public BiomobyObjectActivity createActivity() {
+ return new BiomobyObjectActivity();
+ }
+
+ @Override
+ public URI getActivityURI() {
+ return URI.create(BiomobyObjectActivity.URI);
+ }
+
+ @Override
+ public Object createActivityConfiguration() {
+ return new BiomobyObjectActivityConfigurationBean();
+ }
+
+}
[02/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
new file mode 100644
index 0000000..43b87f1
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.actions;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+public class SoaplabActivityConfigurationAction extends ActivityConfigurationAction {
+
+ private static final long serialVersionUID = 5076721332542691094L;
+ private final Frame owner;
+ public static final String CONFIGURE_SOAPLAB_ACTIVITY = "Configure Soaplab";
+ private final EditManager editManager;
+ private final FileManager fileManager;
+
+ public SoaplabActivityConfigurationAction(Activity activity, Frame owner,
+ EditManager editManager, FileManager fileManager,
+ ActivityIconManager activityIconManager, ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ super(activity, activityIconManager, serviceDescriptionRegistry);
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ putValue(Action.NAME, CONFIGURE_SOAPLAB_ACTIVITY);
+ this.owner = owner;
+ }
+
+ public void actionPerformed(ActionEvent action) {
+ ActivityConfigurationDialog currentDialog = ActivityConfigurationAction.getDialog(getActivity());
+ if (currentDialog != null) {
+ currentDialog.toFront();
+ return;
+ }
+
+ final SoaplabConfigurationPanel panel = new SoaplabConfigurationPanel(getActivity());
+ final ActivityConfigurationDialog dialog = new ActivityConfigurationDialog(
+ getActivity(), panel, editManager);
+
+ ActivityConfigurationAction.setDialog(getActivity(), dialog, fileManager);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
new file mode 100644
index 0000000..9b4b0c8
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.actions;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JCheckBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.TitledBorder;
+
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationPanel;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+@SuppressWarnings("serial")
+public class SoaplabConfigurationPanel extends ActivityConfigurationPanel {
+
+// ActionListener closeClicked;
+// ActionListener applyClicked;
+
+ private JTextField intervalMaxField;
+ private JTextField intervalField;
+ private JTextField backoffField;
+ private JCheckBox allowPolling;
+
+ public SoaplabConfigurationPanel(Activity activity) {
+ super(activity);
+ initialise();
+ }
+
+ public boolean isAllowPolling() {
+ return allowPolling.isSelected();
+ }
+
+ public int getInterval() {
+ return Integer.parseInt(intervalField.getText());
+ }
+
+ public int getIntervalMax() {
+ return Integer.parseInt(intervalMaxField.getText());
+ }
+
+ public double getBackoff() {
+ return Double.parseDouble(backoffField.getText());
+ }
+
+ @Override
+ protected void initialise() {
+ super.initialise();
+ removeAll();
+
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+ JPanel interval = new JPanel();
+ interval.setLayout(new BorderLayout());
+ interval.setBorder(new TitledBorder("Interval"));
+
+ JPanel intervalMax = new JPanel();
+ intervalMax.setLayout(new BorderLayout());
+ intervalMax.setBorder(new TitledBorder("Max interval"));
+
+ JPanel backoff = new JPanel();
+ backoff.setLayout(new BorderLayout());
+ backoff.setBorder(new TitledBorder("Backoff"));
+
+ intervalField = new JTextField(getJson().get("pollingInterval").asText());
+ intervalMaxField = new JTextField(getJson().get("pollingIntervalMax").asText());
+ backoffField = new JTextField(getJson().get("pollingBackoff").asText());
+
+ interval.add(intervalField, BorderLayout.CENTER);
+ intervalMax.add(intervalMaxField);
+ backoff.add(backoffField);
+
+ allowPolling = new JCheckBox("Polling?", getJson().get("pollingInterval").intValue() != 0);
+ allowPolling.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ updateEnableForPollingFlag();
+ }
+ });
+
+ updateEnableForPollingFlag();
+ JPanel allowPollingPanel = new JPanel();
+ allowPollingPanel.setLayout(new BorderLayout());
+ allowPollingPanel.add(allowPolling, BorderLayout.WEST);
+ add(allowPollingPanel);
+ add(interval);
+ add(intervalMax);
+ add(backoff);
+ add(Box.createGlue());
+ validate();
+ }
+
+ @Override
+ public void noteConfiguration() {
+ if (validateValues()) {
+ int interval = 0;
+ int intervalMax = 0;
+ double backoff = 1.1;
+
+ if (isAllowPolling()) {
+ interval = getInterval();
+ intervalMax = getIntervalMax();
+ backoff = getBackoff();
+ }
+
+ getJson().put("pollingBackoff", backoff);
+ getJson().put("pollingInterval", interval);
+ getJson().put("pollingIntervalMax", intervalMax);
+ }
+ }
+
+ @Override
+ public boolean checkValues() {
+ // TODO Not yet implemented
+ return true;
+ }
+
+ private void updateEnableForPollingFlag() {
+ boolean enabled = allowPolling.isSelected();
+ intervalField.setEnabled(enabled);
+ intervalMaxField.setEnabled(enabled);
+ backoffField.setEnabled(enabled);
+ }
+
+ public boolean validateValues() {
+ if (allowPolling.isSelected()) {
+ try {
+ new Integer(intervalField.getText());
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "The interval field must be a valid integer",
+ "Invalid value", JOptionPane.ERROR_MESSAGE);
+ return false;
+
+ }
+
+ try {
+ new Integer(intervalMaxField.getText());
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null,
+ "The maximum interval field must be a valid integer", "Invalid value",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+
+ }
+
+ try {
+ new Double(backoffField.getText());
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, "The backoff field must be a valid float",
+ "Invalid value", JOptionPane.ERROR_MESSAGE);
+ return false;
+
+ }
+ }
+
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/menu/ConfigureSoaplabActivityMenuAction.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/menu/ConfigureSoaplabActivityMenuAction.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/menu/ConfigureSoaplabActivityMenuAction.java
new file mode 100644
index 0000000..f182ecb
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/menu/ConfigureSoaplabActivityMenuAction.java
@@ -0,0 +1,54 @@
+package net.sf.taverna.t2.activities.soaplab.menu;
+
+import javax.swing.Action;
+
+import net.sf.taverna.t2.activities.soaplab.actions.SoaplabActivityConfigurationAction;
+import net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.ui.menu.ContextualMenuComponent;
+import net.sf.taverna.t2.ui.menu.MenuComponent;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.activitytools.AbstractConfigureActivityMenuAction;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+
+public class ConfigureSoaplabActivityMenuAction extends AbstractConfigureActivityMenuAction
+ implements MenuComponent, ContextualMenuComponent {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public ConfigureSoaplabActivityMenuAction() {
+ super(SoaplabServiceDescription.ACTIVITY_TYPE);
+ }
+
+ @Override
+ protected Action createAction() {
+ SoaplabActivityConfigurationAction configAction = new SoaplabActivityConfigurationAction(
+ findActivity(), getParentFrame(), editManager, fileManager, activityIconManager,
+ serviceDescriptionRegistry);
+ configAction.putValue(Action.NAME,
+ SoaplabActivityConfigurationAction.CONFIGURE_SOAPLAB_ACTIVITY);
+ addMenuDots(configAction);
+ return configAction;
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/MissingSoaplabException.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/MissingSoaplabException.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/MissingSoaplabException.java
new file mode 100644
index 0000000..594a7a2
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/MissingSoaplabException.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MissingSoaplabException.java,v $
+ * Revision $Revision: 1.3 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/11/19 17:33:04 $
+ * by $Author: anenadic $
+ * Created on 4 Sep 2006
+ *****************************************************************/
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+@SuppressWarnings("serial")
+public class MissingSoaplabException extends Exception {
+
+ public MissingSoaplabException(String msg) {
+ super(msg);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabActivityIcon.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabActivityIcon.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabActivityIcon.java
new file mode 100644
index 0000000..f9d273b
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabActivityIcon.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.net.URI;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI;
+
+/**
+ *
+ * @author Alex Nenadic
+ *
+ */
+public class SoaplabActivityIcon implements ActivityIconSPI{
+
+ private static Icon icon;
+
+ public int canProvideIconScore(URI activityType) {
+ if (SoaplabServiceDescription.ACTIVITY_TYPE.equals(activityType))
+ return DEFAULT_ICON + 1;
+ else
+ return NO_ICON;
+ }
+
+ public Icon getIcon(URI activityType) {
+ return getSoaplabIcon();
+ }
+
+ public static Icon getSoaplabIcon() {
+ if (icon == null) {
+ icon = new ImageIcon(SoaplabActivityIcon.class
+ .getResource("/soaplab.png"));
+ }
+ return icon;
+ }
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabCategory.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabCategory.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabCategory.java
new file mode 100644
index 0000000..47f994c
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabCategory.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: SoaplabCategory.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/09/04 13:40:38 $
+ * by $Author: sowen70 $
+ * Created on 4 Sep 2006
+ *****************************************************************/
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SoaplabCategory {
+
+ private String category;
+ private List<String> services = new ArrayList<String>();
+
+ public SoaplabCategory(String category) {
+ this.category=category;
+ }
+
+ public boolean addService(String service) {
+ return services.add(service);
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public List<String> getServices() {
+ return services;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabScavengerAgent.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabScavengerAgent.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabScavengerAgent.java
new file mode 100644
index 0000000..fe428ec
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabScavengerAgent.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: SoaplabScavengerAgent.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/09/04 13:40:37 $
+ * by $Author: sowen70 $
+ * Created on 4 Sep 2006
+ *****************************************************************/
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.rpc.ServiceException;
+
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.log4j.Logger;
+
+/**
+ * An agent to query Soaplab server to determine the available categories and services.
+ * @author sowen
+ *
+ */
+
+public class SoaplabScavengerAgent {
+
+ private static Logger logger = Logger.getLogger(SoaplabScavengerAgent.class);
+
+ /**
+ * Returns a list of soaplab categories, containing a list of their services.
+ * Throws MissingSoaplabException if an installation cannot be found.
+ */
+ public static List<SoaplabCategory> load(String base) throws MissingSoaplabException{
+ List<SoaplabCategory> categories=new ArrayList<SoaplabCategory>();
+
+ // Get the categories for this installation
+ boolean foundAnInstallation = loadCategories(base + "AnalysisFactory",categories);
+
+ // Yes, bitwise OR is on purpose, to make sure the second
+ // loadCategories() is always run. Do NOT replace with
+ // foundInstallation = foundInstallation || getCategories(..)
+ foundAnInstallation |= loadCategories(base + "GowlabFactory",categories);
+ if (!foundAnInstallation) {
+ // Neither Soaplab nor Gowlab were found, probably a fault
+ throw new MissingSoaplabException("Unable to locate a soaplab installation at \n" + base);
+ }
+
+ return categories;
+
+ }
+
+
+ private static boolean loadCategories(String categoryBase, List<SoaplabCategory>cats) {
+ boolean foundSome = false;
+ String[] categories;
+ try {
+ categories = (String[]) callWebService(categoryBase, "getAvailableCategories", new Object[0]);
+ } catch (Exception e) {
+ logger.debug("Missing category: "+categoryBase, e);
+ return false;
+ }
+ // Iterate over all the categories, creating new child nodes
+ for (int i = 0; i < categories.length; i++) {
+ String[] services;
+ try {
+ services = (String[]) callWebService(categoryBase, "getAvailableAnalysesInCategory", new Object[] {categories[i]});
+ } catch (Exception e) {
+ logger.info("Skipping category " + categories[i], e);
+ continue;
+ }
+ if (services.length == 0) {
+ // Avoid creating empty treenodes
+ continue;
+ }
+
+ SoaplabCategory category=new SoaplabCategory(categories[i]);
+ cats.add(category);
+
+ foundSome = true;
+ // Iterate over the services
+ for (int j = 0; j < services.length; j++) {
+ category.addService(services[j]);
+ }
+ }
+ return foundSome;
+ }
+
+ public static Object callWebService(String target, String operation,
+ Object[] parameters) throws ServiceException, RemoteException {
+ Service service = new Service();
+ Call call = (Call) service.createCall();
+ call.setTargetEndpointAddress(target);
+ // No need to do new Qname(operation) with unspecified namespaces
+ call.setOperationName(operation);
+ return call.invoke(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
new file mode 100644
index 0000000..99a25b3
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
@@ -0,0 +1,131 @@
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.Icon;
+
+import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class SoaplabServiceDescription extends ServiceDescription {
+
+ public static final URI ACTIVITY_TYPE = URI.create("http://ns.taverna.org.uk/2010/activity/soaplab");
+
+ private final static String SOAPLAB = "Soaplab @ ";
+
+ private String category;
+ private String operation;
+ private URI endpoint;
+ private List<String> types;
+
+ private String name;
+
+ public List<String> getTypes() {
+ return types;
+ }
+
+ /**
+ * @return the category
+ */
+ public String getCategory() {
+ return category;
+ }
+
+ /**
+ * @param category
+ * the category to set
+ */
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ /**
+ * @return the operation
+ */
+ public String getOperation() {
+ return operation;
+ }
+
+ /**
+ * @param operation
+ * the operation to set
+ */
+ public void setOperation(final String operation) {
+ this.operation = operation;
+
+ String name = operation;
+ int finalColon = operation.lastIndexOf(":");
+ if (finalColon != -1) {
+ name = operation.substring(finalColon + 1);
+ }
+ int finalDot = operation.lastIndexOf(".");
+ if (finalDot != -1) {
+ name = operation.substring(finalDot + 1);
+ }
+ setName(name);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ @Override
+ public URI getActivityType() {
+ return ACTIVITY_TYPE;
+ }
+
+ @Override
+ public Configuration getActivityConfiguration() {
+ Configuration configuration = new Configuration();
+ configuration.setType(ACTIVITY_TYPE.resolve("#Config"));
+ ((ObjectNode) configuration.getJson()).put("endpoint", getEndpoint().toASCIIString() + getOperation());
+ ((ObjectNode) configuration.getJson()).put("pollingInterval", 0);
+ ((ObjectNode) configuration.getJson()).put("pollingBackoff", 1.0);
+ ((ObjectNode) configuration.getJson()).put("pollingIntervalMax", 0);
+ return configuration;
+ }
+
+ @Override
+ public Icon getIcon() {
+ return SoaplabActivityIcon.getSoaplabIcon();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public List<String> getPath() {
+ List<String> path = new ArrayList<String>();
+ path.add(SOAPLAB + getEndpoint());
+ path.add(getCategory());
+ // Don't use getTypes() - as we end up
+ // with double entries..
+ return path;
+ }
+
+ public void setTypes(List<String> types) {
+ this.types = types;
+ }
+
+ public void setEndpoint(URI endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public URI getEndpoint() {
+ return endpoint;
+ }
+
+ @Override
+ protected List<Object> getIdentifyingData() {
+ return Arrays.<Object>asList(getEndpoint(), getOperation());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProvider.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProvider.java
new file mode 100644
index 0000000..54080c9
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProvider.java
@@ -0,0 +1,183 @@
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.net.URI;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.Icon;
+import javax.xml.rpc.ServiceException;
+
+import net.sf.taverna.t2.activities.soaplab.Soap;
+import net.sf.taverna.t2.servicedescriptions.AbstractConfigurableServiceProvider;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+
+import org.apache.log4j.Logger;
+
+public class SoaplabServiceProvider extends
+ AbstractConfigurableServiceProvider<SoaplabServiceProviderConfig> {
+
+ // To avoid hammering the soaplab service
+ private static final int DELAY_MS = 100;
+ private static final int DESCRIPTION_UPDATE_INTERVAL_MS = 2000;
+
+ private static Logger logger = Logger
+ .getLogger(SoaplabServiceProvider.class);
+
+ private static final String SOAPLAB_SERVICE = "Soaplab service";
+ private static final boolean FIND_DETAILS = false;
+
+ private static final URI providerId = URI
+ .create("http://taverna.sf.net/2010/service-provider/soaplab");
+
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public SoaplabServiceProvider() {
+ super(new SoaplabServiceProviderConfig(
+ "http://somehost/soaplab/services/"));
+ }
+
+ public void findServiceDescriptionsAsync(
+ FindServiceDescriptionsCallBack callBack) {
+ List<SoaplabServiceDescription> descriptions = findSoaplabServices(callBack);
+ if (descriptions == null) {
+ return;
+ }
+ callBack.partialResults(descriptions);
+
+ if (FIND_DETAILS) {
+ if (findSoaplabDetails(descriptions, callBack)) {
+ callBack.finished();
+ }
+ } else {
+ callBack.finished();
+ }
+ }
+
+ public List<SoaplabServiceProviderConfig> getDefaultConfigurations() {
+
+ List<SoaplabServiceProviderConfig> defaults = new ArrayList<SoaplabServiceProviderConfig>();
+
+ // If defaults have failed to load from a configuration file then load them here.
+ if (!serviceDescriptionRegistry.isDefaultSystemConfigurableProvidersLoaded()){
+ defaults.add(new SoaplabServiceProviderConfig(
+ "http://wsembnet.vital-it.ch/soaplab2-axis/services/"));
+ } // else return an empty list
+
+ return defaults;
+ }
+
+ public Icon getIcon() {
+ return SoaplabActivityIcon.getSoaplabIcon();
+ }
+
+ public String getName() {
+ return SOAPLAB_SERVICE;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected boolean findSoaplabDetails(
+ List<SoaplabServiceDescription> descriptions,
+ FindServiceDescriptionsCallBack callBack) {
+ Date lastUpdate = new Date();
+ // We'll fetch more details and update the descriptions in the
+ // background
+ List<SoaplabServiceDescription> updatedDescriptions = new ArrayList<SoaplabServiceDescription>();
+ for (SoaplabServiceDescription serviceDescription : descriptions) {
+ try {
+ Date now = new Date();
+ if (now.getTime() - lastUpdate.getTime() > DESCRIPTION_UPDATE_INTERVAL_MS) {
+ if (!updatedDescriptions.isEmpty()) {
+ callBack.partialResults(updatedDescriptions);
+ updatedDescriptions = new ArrayList<SoaplabServiceDescription>();
+ }
+ lastUpdate = now;
+ }
+ Thread.sleep(DELAY_MS);
+ URI soaplabEndpoint = serviceProviderConfig.getEndpoint();
+ Map info = (Map) Soap.callWebService(soaplabEndpoint
+ .toASCIIString()
+ + "/" + serviceDescription.getOperation(),
+ "getAnalysisType"); // Get the description element from
+ // the map
+ String description = (String) info.get("description");
+ if (description != null) {
+ serviceDescription.setDescription(description);
+ }
+ updatedDescriptions.add(serviceDescription);
+ String type = (String) info.get("type");
+ if (type != null) {
+ serviceDescription.setTypes(Arrays.asList(type.split(",")));
+ }
+ } catch (ClassCastException e) {
+ logger.warn("Can't read descriptions for soaplab service "
+ + serviceDescription, e);
+ callBack.warning("Can't read descriptions for soaplab service "
+ + serviceDescription.getOperation());
+ } catch (ServiceException e) {
+ logger.warn("Can't read descriptions for soaplab service "
+ + serviceDescription, e);
+ callBack.warning("Can't read descriptions for soaplab service "
+ + serviceDescription.getOperation());
+ } catch (RemoteException e) {
+ logger.warn("Can't read descriptions for soaplab service "
+ + serviceDescription, e);
+ callBack.warning("Can't read descriptions for soaplab service "
+ + serviceDescription.getOperation());
+ } catch (InterruptedException ex) {
+ callBack.fail("Thread was interrupted", ex);
+ return false;
+ }
+ }
+ if (!updatedDescriptions.isEmpty()) {
+ callBack.partialResults(updatedDescriptions);
+ }
+ return true;
+ }
+
+ protected List<SoaplabServiceDescription> findSoaplabServices(
+ FindServiceDescriptionsCallBack callBack) {
+ List<SoaplabServiceDescription> descriptions = new ArrayList<SoaplabServiceDescription>();
+ URI soaplabEndpoint = serviceProviderConfig.getEndpoint();
+ callBack.status("Connecting to Soaplab:" + soaplabEndpoint);
+ List<SoaplabCategory> categories;
+ try {
+ categories = SoaplabScavengerAgent.load(soaplabEndpoint
+ .toASCIIString());
+ } catch (MissingSoaplabException ex) {
+ String message = "There was an error with the soaplab: "
+ + soaplabEndpoint;
+ callBack.fail(message, ex);
+ return null;
+ }
+ for (SoaplabCategory cat : categories) {
+ for (String service : cat.getServices()) {
+ SoaplabServiceDescription item = new SoaplabServiceDescription();
+ item.setCategory(cat.getCategory());
+ item.setOperation(service);
+ item.setEndpoint(soaplabEndpoint);
+ descriptions.add(item);
+ }
+ }
+ return descriptions;
+ }
+
+ @Override
+ protected List<? extends Object> getIdentifyingData() {
+ List<String> result;
+ result = Arrays.asList(getConfiguration().getEndpoint().toString());
+ return result;
+ }
+
+ public String getId() {
+ return providerId.toString();
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProviderConfig.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProviderConfig.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProviderConfig.java
new file mode 100644
index 0000000..d1e86da
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceProviderConfig.java
@@ -0,0 +1,38 @@
+package net.sf.taverna.t2.activities.soaplab.servicedescriptions;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.lang.beans.PropertyAnnotated;
+import net.sf.taverna.t2.lang.beans.PropertyAnnotation;
+
+public class SoaplabServiceProviderConfig extends PropertyAnnotated {
+
+ private URI endpoint;
+
+ public SoaplabServiceProviderConfig() {
+ }
+
+ public SoaplabServiceProviderConfig(String endpointURI) {
+ this.setEndpoint(URI.create(endpointURI.trim()));
+ }
+
+ @PropertyAnnotation(displayName = "Soaplab location", preferred = true)
+ public URI getEndpoint() {
+ return endpoint;
+ }
+
+ public String toString() {
+ return getEndpoint().toString();
+ }
+
+ public void setEndpoint(URI endpoint) {
+ String uriString = endpoint.toString();
+ if (!uriString.endsWith("/")) {
+ uriString = uriString + "/";
+ this.endpoint = URI.create(uriString);
+ } else {
+ this.endpoint = endpoint;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
new file mode 100644
index 0000000..de51f23
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.views;
+
+import java.awt.Frame;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+
+import javax.swing.Action;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import net.sf.taverna.t2.activities.soaplab.actions.SoaplabActivityConfigurationAction;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.actions.activity.HTMLBasedActivityContextualView;
+
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+import uk.org.taverna.scufl2.api.configurations.Configuration;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class SoaplabActivityContextualView extends HTMLBasedActivityContextualView {
+
+ private static Logger logger = Logger.getLogger(SoaplabActivityContextualView.class);
+
+ private static final long serialVersionUID = -6470801873448104509L;
+
+ private final EditManager editManager;
+
+ private final FileManager fileManager;
+
+ private final ActivityIconManager activityIconManager;
+
+ private final ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public SoaplabActivityContextualView(Activity activity, EditManager editManager,
+ FileManager fileManager, ActivityIconManager activityIconManager,
+ ColourManager colourManager, ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ super(activity, colourManager);
+ this.editManager = editManager;
+ this.fileManager = fileManager;
+ this.activityIconManager = activityIconManager;
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+ @Override
+ public String getViewTitle() {
+ return "Soaplab service";
+ }
+
+ @Override
+ protected String getRawTableRowsHtml() {
+ Configuration configuration = getConfigBean();
+ JsonNode json = configuration.getJson();
+ String html = "<tr><td>Endpoint</td><td>" + json.get("endpoint").textValue() + "</td></tr>";
+ html += "<tr><td>Polling interval</td><td>" + json.get("pollingInterval").asText()
+ + "</td></tr>";
+ html += "<tr><td>Polling backoff</td><td>" + json.get("pollingBackoff").asText()
+ + "</td></tr>";
+ html += "<tr><td>Polling interval max</td><td>" + json.get("pollingIntervalMax").asText()
+ + "</td></tr>";
+ // html += "<tr><td>SOAPLAB Metadata</td><td>" + getMetadata()
+ // + "</td></tr>";
+ return html;
+ }
+
+ @Override
+ public Action getConfigureAction(Frame owner) {
+ return new SoaplabActivityConfigurationAction(getActivity(), owner, editManager,
+ fileManager, activityIconManager, serviceDescriptionRegistry);
+ }
+
+ private String getMetadata() {
+ try {
+ Configuration configuration = getConfigBean();
+ JsonNode json = configuration.getJson();
+ String endpoint = json.get("endpoint").textValue();
+ Call call = (Call) new Service().createCall();
+ call.setTimeout(new Integer(0));
+ call.setTargetEndpointAddress(endpoint);
+ call.setOperationName(new QName("describe"));
+ String metadata = (String) call.invoke(new Object[0]);
+ logger.info(metadata);
+ // Old impl, returns a tree of the XML
+ // ColXMLTree tree = new ColXMLTree(metadata);
+ URL sheetURL = SoaplabActivityContextualView.class
+ .getResource("/analysis_metadata_2_html.xsl");
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ logger.info(sheetURL.toString());
+ Templates stylesheet = transformerFactory.newTemplates(new StreamSource(sheetURL
+ .openStream()));
+ Transformer transformer = stylesheet.newTransformer();
+ StreamSource inputStream = new StreamSource(new ByteArrayInputStream(
+ metadata.getBytes()));
+ ByteArrayOutputStream transformedStream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(transformedStream);
+ transformer.transform(inputStream, result);
+ transformedStream.flush();
+ transformedStream.close();
+ // String summaryText = "<html><head>"
+ // + WorkflowSummaryAsHTML.STYLE_NOBG + "</head>"
+ // + transformedStream.toString() + "</html>";
+ // JEditorPane metadataPane = new ColJEditorPane("text/html",
+ // summaryText);
+ // metadataPane.setText(transformedStream.toString());
+ // // logger.info(transformedStream.toString());
+ // JScrollPane jsp = new JScrollPane(metadataPane,
+ // JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ // JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ // jsp.setPreferredSize(new Dimension(0, 0));
+ // jsp.getVerticalScrollBar().setValue(0);
+ return transformedStream.toString();
+ } catch (Exception ex) {
+ return "<font color=\"red\">Error</font><p>An exception occured while trying to fetch Soaplab metadata from the server. The error was :<pre>"
+ + ex.getMessage() + "</pre>";
+
+ }
+ }
+
+ @Override
+ public int getPreferredPosition() {
+ return 100;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
new file mode 100644
index 0000000..23e94d8
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.views;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabServiceDescription;
+import net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry;
+import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
+import net.sf.taverna.t2.workbench.configuration.colour.ColourManager;
+import net.sf.taverna.t2.workbench.edits.EditManager;
+import net.sf.taverna.t2.workbench.file.FileManager;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+public class SoaplabActivityViewFactory implements ContextualViewFactory<Activity> {
+
+ private EditManager editManager;
+ private FileManager fileManager;
+ private ActivityIconManager activityIconManager;
+ private ColourManager colourManager;
+ private ServiceDescriptionRegistry serviceDescriptionRegistry;
+
+ public boolean canHandle(Object object) {
+ return object instanceof Activity && ((Activity) object).getType().equals(SoaplabServiceDescription.ACTIVITY_TYPE);
+ }
+
+ public List<ContextualView> getViews(Activity activity) {
+ return Arrays.asList(new ContextualView[] { new SoaplabActivityContextualView(activity,
+ editManager, fileManager, activityIconManager, colourManager, serviceDescriptionRegistry) });
+ }
+
+ public void setEditManager(EditManager editManager) {
+ this.editManager = editManager;
+ }
+
+ public void setFileManager(FileManager fileManager) {
+ this.fileManager = fileManager;
+ }
+
+ public void setActivityIconManager(ActivityIconManager activityIconManager) {
+ this.activityIconManager = activityIconManager;
+ }
+
+ public void setColourManager(ColourManager colourManager) {
+ this.colourManager = colourManager;
+ }
+
+ public void setServiceDescriptionRegistry(ServiceDescriptionRegistry serviceDescriptionRegistry) {
+ this.serviceDescriptionRegistry = serviceDescriptionRegistry;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
new file mode 100644
index 0000000..fb73ade
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabServiceProvider
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
new file mode 100644
index 0000000..1eeb850
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.ui.menu.MenuComponent
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.soaplab.menu.ConfigureSoaplabActivityMenuAction
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
new file mode 100644
index 0000000..0bb5227
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabActivityIcon
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
new file mode 100644
index 0000000..ea7da0b
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/services/net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.soaplab.views.SoaplabActivityViewFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context-osgi.xml b/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context-osgi.xml
new file mode 100644
index 0000000..f7e486e
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context-osgi.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="SoaplabActivityIcon" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconSPI" />
+
+ <service ref="SoaplabServiceProvider">
+ <interfaces>
+ <beans:value>net.sf.taverna.t2.servicedescriptions.ServiceDescriptionProvider</beans:value>
+ <beans:value>net.sf.taverna.t2.servicedescriptions.ConfigurableServiceProvider</beans:value>
+ </interfaces>
+ </service>
+
+ <service ref="ConfigureSoaplabActivityMenuAction" auto-export="interfaces" />
+
+ <service ref="SoaplabActivityViewFactory" interface="net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory" />
+
+ <reference id="editManager" interface="net.sf.taverna.t2.workbench.edits.EditManager" />
+ <reference id="fileManager" interface="net.sf.taverna.t2.workbench.file.FileManager" />
+ <reference id="activityIconManager" interface="net.sf.taverna.t2.workbench.activityicons.ActivityIconManager" />
+ <reference id="colourManager" interface="net.sf.taverna.t2.workbench.configuration.colour.ColourManager" />
+ <reference id="serviceDescriptionRegistry" interface="net.sf.taverna.t2.servicedescriptions.ServiceDescriptionRegistry" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context.xml b/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context.xml
new file mode 100644
index 0000000..7f99ff2
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/META-INF/spring/soaplab-activity-ui-context.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="SoaplabActivityIcon" class="net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabActivityIcon" />
+
+ <bean id="SoaplabServiceProvider" class="net.sf.taverna.t2.activities.soaplab.servicedescriptions.SoaplabServiceProvider">
+ <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" />
+ </bean>
+
+ <bean id="ConfigureSoaplabActivityMenuAction" class="net.sf.taverna.t2.activities.soaplab.menu.ConfigureSoaplabActivityMenuAction">
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" />
+ </bean>
+
+ <bean id="SoaplabActivityViewFactory" class="net.sf.taverna.t2.activities.soaplab.views.SoaplabActivityViewFactory" >
+ <property name="editManager" ref="editManager" />
+ <property name="fileManager" ref="fileManager" />
+ <property name="activityIconManager" ref="activityIconManager" />
+ <property name="colourManager" ref="colourManager" />
+ <property name="serviceDescriptionRegistry" ref="serviceDescriptionRegistry" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/analysis_metadata_2_html.xsl
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/analysis_metadata_2_html.xsl b/taverna-soaplab-activity-ui/src/main/resources/analysis_metadata_2_html.xsl
new file mode 100644
index 0000000..5095e5c
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/main/resources/analysis_metadata_2_html.xsl
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- ===================================================================== -->
+<!-- Converting analysis metadata returned by Soaplab Web Services to HTML -->
+<!-- (http://www.ebi.ac.uk/soaplab/) -->
+<!-- Author: Martin Senger (senger@ebi.ac.uk) -->
+<!-- ===================================================================== -->
+
+<!-- $Id: analysis_metadata_2_html.xsl,v 1.1 2008/07/14 15:27:42 iandunlop Exp $ -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+ <xsl:output method="html"/>
+
+ <!-- the main document body -->
+ <xsl:template match="/">
+ <body>
+ <xsl:apply-templates/>
+ </body>
+ </xsl:template>
+
+ <!-- analysis -->
+ <xsl:template match="/DsLSRAnalysis/analysis">
+
+ <!-- analysis name -->
+ <table border="0" cellpadding="2" cellspacing="3" width="98%" align="center"><tr><th bgcolor="#eeeedd">
+ <font size="+1"><xsl:value-of select="@name"/></font>
+ </th></tr></table>
+
+ <!-- analysis metadata -->
+ <table border="0" cellspacing="1" cellpadding="1" width="99%" align="center"><tr>
+ <td>
+ <table border="0" cellspacing="2">
+ <xsl:apply-templates select="description" mode="as-row"/>
+ <xsl:apply-templates select="analysis_extension/app_info/@*[local-name != 'help_URL']" mode="as-row"/>
+ <xsl:apply-templates select="@*[local-name() != 'name']" mode="as-row"/>
+ <tr><td>Help URL</td><td><a href="{analysis_extension/app_info/@help_URL}"><xsl:value-of select="analysis_extension/app_info/@help_URL"/></a></td></tr>
+ </table>
+ </td></tr></table>
+
+ <!-- inputs/outputs metadata -->
+ <table border="0" width="98%" cellpadding="2" cellspacing="1" align="center">
+ <tr><td colspan="2" bgcolor="#eeeedd"> <b>Outputs</b> </td></tr>
+ <xsl:apply-templates select="output"/>
+ <tr><td colspan="2" bgcolor="#eeeedd"> <b>Inputs</b> </td></tr>
+ <xsl:apply-templates select="input"/>
+ </table>
+
+ </xsl:template>
+
+ <!-- metadata about one input or output -->
+ <xsl:template match="input|output">
+ <xsl:variable name="param_name" select="@name"/>
+ <tr bgcolor="#eae9c2">
+ <td valign="top"><b><xsl:value-of select="@name"/></b></td>
+ <td><table border="0" cellspacing="1" cellpadding="1" bgcolor="white" width="100%">
+ <xsl:apply-templates select="@*[local-name() != 'name']" mode="as-row"/>
+ <xsl:apply-templates select="allowed" mode="as-row"/>
+ <xsl:apply-templates select="../analysis_extension/parameter/base[@name =$param_name]/*" mode="as-row"/>
+ <xsl:apply-templates select="../analysis_extension/parameter/base[concat(@name,'_url') =$param_name]/*" mode="as-row"/>
+ <xsl:apply-templates select="../analysis_extension/parameter/base[concat(@name,'_direct_data')=$param_name]/*" mode="as-row"/>
+ <xsl:apply-templates select="../analysis_extension/parameter/base[concat(@name,'_usa') =$param_name]/*" mode="as-row"/>
+ </table></td>
+ </tr>
+ </xsl:template>
+
+ <!-- attributes and elements expressed as a (bold)name and value -->
+ <xsl:template match="@*[local-name() != 'help_URL']|description|default|prompt|help" mode="as-row">
+ <tr>
+ <td valign="top" width="80"><em><xsl:value-of select="local-name()"/></em></td>
+ <td><xsl:value-of select="."/></td>
+ </tr>
+ </xsl:template>
+
+ <!-- more-values elements -->
+ <xsl:template match="allowed" mode="as-row">
+
+ <xsl:if test="position() = 1">
+ <xsl:text disable-output-escaping = "yes"><tr></xsl:text>
+ <td valign="top" width="80"><em><xsl:value-of select="local-name()"/></em></td>
+ <xsl:text disable-output-escaping = "yes"><td></xsl:text>
+ </xsl:if>
+
+ <xsl:value-of select="."/>
+ <xsl:if test="position() != last()">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
+
+ <xsl:if test="position() = last()">
+ <xsl:text disable-output-escaping = "yes"></td></xsl:text>
+ <xsl:text disable-output-escaping = "yes"></tr></xsl:text>
+ </xsl:if>
+
+ </xsl:template>
+
+</xsl:stylesheet>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/main/resources/soaplab.png
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/resources/soaplab.png b/taverna-soaplab-activity-ui/src/main/resources/soaplab.png
new file mode 100644
index 0000000..b86d848
Binary files /dev/null and b/taverna-soaplab-activity-ui/src/main/resources/soaplab.png differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java b/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
new file mode 100644
index 0000000..c4d683d
--- /dev/null
+++ b/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab.views;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import net.sf.taverna.t2.activities.soaplab.actions.SoaplabActivityConfigurationAction;
+import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import uk.org.taverna.scufl2.api.activity.Activity;
+
+public class TestSoaplabActivityContextualView {
+
+ Activity a;
+
+ @Before
+ public void setup() throws Exception {
+ a=new Activity();
+ }
+
+ @Test
+ @Ignore("Integration test")
+ public void testConfigureAction() throws Exception {
+ ContextualView view = new SoaplabActivityContextualView(a, null, null, null, null, null);
+ assertNotNull("the action should not be null",view.getConfigureAction(null));
+ assertTrue("The action should be a SoaplabAcitivyConfigurationAction",view.getConfigureAction(null) instanceof SoaplabActivityConfigurationAction);
+ }
+
+ private void run() throws Exception
+ {
+ setup();
+ ContextualView view = new SoaplabActivityContextualView(a, null, null, null, null, null);
+ view.setVisible(true);
+ }
+
+ public static void main(String[] args) throws Exception {
+ new TestSoaplabActivityContextualView().run();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/pom.xml b/taverna-soaplab-activity/pom.xml
new file mode 100644
index 0000000..5459718
--- /dev/null
+++ b/taverna-soaplab-activity/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>soaplab-activity</artifactId>
+ <packaging>bundle</packaging>
+ <name>Taverna 2 Soaplab Activity</name>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>workflowmodel-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>reference-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis</groupId>
+ <artifactId>com.springsource.org.apache.axis</artifactId>
+ <version>${axis.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.rpc</groupId>
+ <artifactId>com.springsource.javax.xml.rpc</artifactId>
+ <version>${xml.rpc.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>activity-test-utils</artifactId>
+ <version>${t2.activities.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-soaplab-activity.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com:taverna/taverna-soaplab-activity.git</developerConnection>
+ <url>https://github.com/taverna/taverna-soaplab-activity</url>
+ <tag>HEAD</tag>
+ </scm>
+
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/Soap.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/Soap.java b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/Soap.java
new file mode 100644
index 0000000..ba9cce6
--- /dev/null
+++ b/taverna-soaplab-activity/src/main/java/net/sf/taverna/t2/activities/soaplab/Soap.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.soaplab;
+
+import java.rmi.RemoteException;
+
+import javax.xml.rpc.ServiceException;
+
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+
+/**
+ * Convenience methods for simpler calling of SOAP services using the Axis
+ * client.
+ *
+ * Note that for complex scenarious you might want to construct the Call object
+ * yourself.
+ *
+ * @author Stian Soiland
+ *
+ */
+public class Soap {
+ /**
+ * Invoke the web service, passing no parameters, and return the result.
+ *
+ * @see callWebService(String target, String operation, Object[] parameters)
+ *
+ */
+ public static Object callWebService(String target, String operation)
+ throws ServiceException, RemoteException {
+ return callWebService(target, operation, new Object[0]);
+ }
+
+ /**
+ * Invoke the web service, passing a single String parameter, and return the result.
+ *
+ * @see callWebService(String target, String operation, Object[] parameters)
+ *
+ */
+ public static Object callWebService(String target, String operation,
+ String parameter) throws ServiceException, RemoteException {
+ return callWebService(target, operation, new String[] { parameter });
+ }
+
+ /**
+ * Invoke the web service and return the result.
+ *
+ * @param target The full URL to the service, example "http://www.ebi.ac.uk/soaplab/services/AnalysisFactory"
+ * @param operation The operation name, example "getAvailableCategories"
+ * @param parameters A (possibly empty) list of parameters
+ * @return The result returned from calling the webservice operation
+ * @throws ServiceException If web service facilities are not available
+ * @throws RemoteException If remote call failed
+ */
+ public static Object callWebService(String target, String operation,
+ Object[] parameters) throws ServiceException, RemoteException {
+ Service service = new Service();
+ Call call = (Call) service.createCall();
+ call.setTargetEndpointAddress(target);
+ // No need to do new Qname(operation) with unspecified namespaces
+ call.setOperationName(operation);
+ return call.invoke(parameters);
+ }
+}
[04/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthChecker.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthChecker.java
new file mode 100644
index 0000000..7db539a
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/BiomobyObjectActivityHealthChecker.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
+
+/**
+ * A health checker for the Biomoby Object activity.
+ *
+ * @author David Withers
+ */
+public class BiomobyObjectActivityHealthChecker extends RemoteHealthChecker {
+
+ public boolean canVisit(Object subject) {
+ if (subject == null) {
+ return false;
+ }
+ if (subject instanceof BiomobyObjectActivity) {
+ return true;
+ }
+ if (subject instanceof DisabledActivity) {
+ return (((DisabledActivity) subject).getActivity() instanceof BiomobyObjectActivity);
+ }
+ return false;
+ }
+
+ public VisitReport visit(Object o, List<Object> ancestors) {
+ Activity activity = (Activity) o;
+ BiomobyObjectActivityConfigurationBean configuration = null;
+ if (activity instanceof BiomobyObjectActivity) {
+ configuration = (BiomobyObjectActivityConfigurationBean) activity.getConfiguration();
+ } else if (activity instanceof DisabledActivity) {
+ configuration = (BiomobyObjectActivityConfigurationBean) ((DisabledActivity) activity).getActivityConfiguration();
+ }
+ return contactEndpoint(activity, configuration.getMobyEndpoint());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncCgiService.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncCgiService.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncCgiService.java
new file mode 100644
index 0000000..552dd34
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncCgiService.java
@@ -0,0 +1,517 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.log4j.Logger;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyPrefixResolver;
+import org.biomoby.shared.parser.MobyTags;
+import org.biomoby.w3c.addressing.EndpointReference;
+import org.jdom.Element;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.omg.lsae.notifications.AnalysisEvent;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+/**
+ * This class contains one method that is used to execute asynchronous HTTP POST
+ * services
+ *
+ * @author Edward Kawas
+ *
+ */
+public class ExecuteAsyncCgiService {
+
+ private static final String GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION = "http://docs.oasis-open.org/wsrf/rpw-2/GetMultipleResourceProperties/GetMultipleResourcePropertiesRequest";
+ private static final String DESTROY_RESOURCE_ACTION = "http://docs.oasis-open.org/wsrf/rlw-2/ImmediateResourceTermination/DestroyRequest";
+
+ private static final String RESOURCE_PROPERTIES_NS = "http://docs.oasis-open.org/wsrf/rp-2";
+ private static final String RESULT_PREFIX = "result_";
+ private static final String STATUS_PREFIX = "status_";
+ private static Logger logger = Logger
+ .getLogger(ExecuteAsyncCgiService.class);
+
+ /**
+ *
+ * @param url
+ * @param serviceName
+ * @param xml
+ * @return
+ */
+ public static String executeMobyCgiAsyncService(String url,
+ String serviceName, String xml) throws MobyException {
+
+ // First, let's get the queryIds
+ org.w3c.dom.Document message = null;
+
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setValidating(false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ message = db.parse(new InputSource(new StringReader(xml)));
+ } catch (Throwable t) {
+ throw new MobyException("Error while parsing input query", t);
+ }
+
+ NodeList l_data = message.getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE, MobyTags.MOBYDATA);
+ if (l_data == null || l_data.getLength() == 0) {
+ l_data = message.getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE_INVALID,
+ MobyTags.MOBYDATA);
+ }
+
+ // Freeing resources
+ message = null;
+
+ if (l_data == null || l_data.getLength() == 0) {
+ throw new MobyException("Empty asynchronous MOBY query!");
+ }
+
+ int nnode = l_data.getLength();
+ String[] queryIds = new String[nnode];
+ String[] tmpQueryIds = new String[nnode];
+ String[] results = new String[nnode];
+ for (int inode = 0; inode < nnode; inode++) {
+ String queryId = null;
+
+ org.w3c.dom.Element mdata = (org.w3c.dom.Element) l_data
+ .item(inode);
+
+ queryId = mdata.getAttribute(MobyTags.QUERYID);
+ if (queryId == null || queryId.length() == 0)
+ queryId = mdata
+ .getAttributeNS(MobyPrefixResolver.MOBY_XML_NAMESPACE,
+ MobyTags.QUERYID);
+ if (queryId == null || queryId.length() == 0)
+ queryId = mdata.getAttributeNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE_INVALID,
+ MobyTags.QUERYID);
+
+ if (queryId == null || queryId.length() == 0) {
+ throw new MobyException(
+ "Unable to extract queryId for outgoing MOBY message");
+ }
+
+ tmpQueryIds[inode] = queryIds[inode] = queryId;
+ results[inode] = null;
+ }
+
+ // Freeing resources
+ l_data = null;
+
+ // Second, let's launch
+ EndpointReference epr = launchCgiAsyncService(url, xml);
+
+ // Third, waiting for the results
+ try {
+ // FIXME - add appropriate values here
+ long pollingInterval = 1000L;
+ double backoff = 1.0;
+
+ // Max: one minute pollings
+ long maxPollingInterval = 60000L;
+
+ // Min: one second
+ if (pollingInterval <= 0L)
+ pollingInterval = 1000L;
+
+ // Backoff: must be bigger than 1.0
+ if (backoff <= 1.0)
+ backoff = 1.5;
+
+ do {
+ try {
+ Thread.sleep(pollingInterval);
+ } catch (InterruptedException ie) {
+ // DoNothing(R)
+ }
+
+ if (pollingInterval != maxPollingInterval) {
+ pollingInterval = (long) ((double) pollingInterval * backoff);
+ if (pollingInterval > maxPollingInterval) {
+ pollingInterval = maxPollingInterval;
+ }
+ }
+ } while (pollAsyncCgiService(serviceName, url, epr, tmpQueryIds,
+ results));
+ } finally {
+
+ // Call destroy on this service ....
+ freeCgiAsyncResources(url, epr);
+
+ }
+
+ // Fourth, assembling back the results
+
+ // Results array already contains mobyData
+ Element[] mobydatas = new Element[results.length];
+ for (int x = 0; x < results.length; x++) {
+ // TODO remove the extra wrapping from our result
+ try {
+ Element inputElement = XMLUtilities.getDOMDocument(results[x])
+ .getRootElement();
+ if (inputElement.getName().indexOf(
+ "GetMultipleResourcePropertiesResponse") >= 0)
+ if (inputElement.getChildren().size() > 0)
+ inputElement = (Element) inputElement.getChildren()
+ .get(0);
+ if (inputElement.getName().indexOf("result_") >= 0)
+ if (inputElement.getChildren().size() > 0)
+ inputElement = (Element) inputElement.getChildren()
+ .get(0);
+ // replace results[x]
+ mobydatas[x] = inputElement;
+ } catch (MobyException e) {
+ // TODO what should i do?
+ }
+ }
+ Element e = null;
+ try {
+ e = XMLUtilities.createMultipleInvokations(mobydatas);
+ } catch (Exception ex) {
+ logger
+ .error("There was a problem creating our XML message ...",
+ ex);
+ }
+ // Fifth, returning results
+ return e == null ? "" : new XMLOutputter(Format.getPrettyFormat())
+ .outputString(e);
+ }
+
+ private static void freeCgiAsyncResources(String endpoint,
+ EndpointReference epr) throws MobyException {
+ // construct the Httpclient
+ HttpClient client = new HttpClient();
+ client.getParams().setParameter("http.useragent", "jMoby/Taverna2");
+ // create the post method
+ PostMethod method = new PostMethod(endpoint + "/destroy");
+
+ // put our data in the request
+ RequestEntity entity;
+ try {
+ entity = new StringRequestEntity(
+ "<Destroy xmlns=\"http://docs.oasis-open.org/wsrf/rl-2\"/>",
+ "text/xml", null);
+ } catch (UnsupportedEncodingException e) {
+ throw new MobyException("Problem posting data to webservice", e);
+ }
+ method.setRequestEntity(entity);
+
+ // set the header
+ StringBuffer httpheader = new StringBuffer();
+ httpheader.append("<moby-wsrf>");
+ httpheader
+ .append("<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
+ + DESTROY_RESOURCE_ACTION + "</wsa:Action>");
+ httpheader
+ .append("<wsa:To xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsu:Id=\"To\">"
+ + endpoint + "</wsa:To>");
+ httpheader
+ .append("<mobyws:ServiceInvocationId xmlns:mobyws=\"http://biomoby.org/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter=\"true\">"
+ + epr.getServiceInvocationId()
+ + "</mobyws:ServiceInvocationId>");
+ httpheader.append("</moby-wsrf>");
+ method.addRequestHeader("moby-wsrf", httpheader.toString().replaceAll(
+ "\r\n", ""));
+ // retry up to 10 times
+ client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ new DefaultHttpMethodRetryHandler(10, true));
+
+ // call the method
+ try {
+ int result = client.executeMethod(method);
+ if (result != HttpStatus.SC_OK)
+ throw new MobyException(
+ "Async HTTP POST service returned code: " + result
+ + "\n" + method.getStatusLine());
+ } catch (IOException e) {
+ throw new MobyException("Problem reading response from webservice",
+ e);
+ } finally {
+ // Release current connection to the connection pool once you are
+ // done
+ method.releaseConnection();
+ }
+ }
+
+ /**
+ *
+ * @param endpoint
+ * the url to the service to call
+ * @param xml
+ * the BioMOBY input message
+ * @return EndpointReference the EPR returned by the service
+ * @throws MobyException
+ */
+ private static EndpointReference launchCgiAsyncService(String endpoint,
+ String xml) throws MobyException {
+ // construct the Httpclient
+ HttpClient client = new HttpClient();
+ client.getParams().setParameter("http.useragent", "jMoby/Taverna2");
+ // create the post method
+ PostMethod method = new PostMethod(endpoint);
+
+ // put our data in the request
+ RequestEntity entity;
+ try {
+ entity = new StringRequestEntity(xml, "text/xml", null);
+ } catch (UnsupportedEncodingException e) {
+ throw new MobyException("Problem posting data to webservice", e);
+ }
+ method.setRequestEntity(entity);
+
+ // retry up to 10 times
+ client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ new DefaultHttpMethodRetryHandler(10, true));
+
+ // call the method
+ try {
+ int result = client.executeMethod(method);
+ if (result != HttpStatus.SC_OK)
+ throw new MobyException(
+ "Async HTTP POST service returned code: " + result
+ + "\n" + method.getStatusLine());
+ return EndpointReference.createFromXML(method.getResponseHeader(
+ "moby-wsrf").getValue());
+ } catch (IOException e) {
+ throw new MobyException("Problem reading response from webservice",
+ e);
+ } finally {
+ // Release current connection to the connection pool once you are
+ // done
+ method.releaseConnection();
+ }
+ }
+
+ private static boolean pollAsyncCgiService(String msName, String url,
+ EndpointReference epr, String[] queryIds, String[] result)
+ throws MobyException {
+ // Needed to remap results
+ HashMap<String, Integer> queryMap = new HashMap<String, Integer>();
+ for (int qi = 0; qi < queryIds.length; qi++) {
+ String queryId = queryIds[qi];
+ if (queryId != null)
+ queryMap.put(queryId, new Integer(qi));
+ }
+
+ if (queryMap.size() == 0)
+ return false;
+
+ // construct the GetMultipleResourceProperties XML
+ StringBuffer xml = new StringBuffer();
+ xml.append("<wsrf-rp:GetMultipleResourceProperties xmlns:wsrf-rp='"
+ + RESOURCE_PROPERTIES_NS
+ + "' xmlns:mobyws='http://biomoby.org/'>");
+ for (String q : queryMap.keySet())
+ xml.append("<wsrf-rp:ResourceProperty>mobyws:" + STATUS_PREFIX + q
+ + "</wsrf-rp:ResourceProperty>");
+ xml.append("</wsrf-rp:GetMultipleResourceProperties>");
+
+ StringBuffer httpheader = new StringBuffer();
+ httpheader.append("<moby-wsrf>");
+ httpheader
+ .append("<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
+ + GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION
+ + "</wsa:Action>");
+ httpheader
+ .append("<wsa:To xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsu:Id=\"To\">"
+ + url + "</wsa:To>");
+ httpheader
+ .append("<mobyws:ServiceInvocationId xmlns:mobyws=\"http://biomoby.org/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter=\"true\">"
+ + epr.getServiceInvocationId()
+ + "</mobyws:ServiceInvocationId>");
+ httpheader.append("</moby-wsrf>");
+
+ AnalysisEvent[] l_ae = null;
+ // First, status from queries
+ String response = "";
+ // construct the Httpclient
+ HttpClient client = new HttpClient();
+ client.getParams().setParameter("http.useragent", "jMoby/Taverna2");
+ // create the post method
+ PostMethod method = new PostMethod(url + "/status");
+ // add the moby-wsrf header (with no newlines)
+ method.addRequestHeader("moby-wsrf", httpheader.toString().replaceAll(
+ "\r\n", ""));
+
+ // put our data in the request
+ RequestEntity entity;
+ try {
+ entity = new StringRequestEntity(xml.toString(), "text/xml", null);
+ } catch (UnsupportedEncodingException e) {
+ throw new MobyException("Problem posting data to webservice", e);
+ }
+ method.setRequestEntity(entity);
+
+ // retry up to 10 times
+ client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ new DefaultHttpMethodRetryHandler(10, true));
+
+ // call the method
+ try {
+ if (client.executeMethod(method) != HttpStatus.SC_OK)
+ throw new MobyException(
+ "Async HTTP POST service returned code: "
+ + method.getStatusCode() + "\n"
+ + method.getStatusLine()
+ + "\nduring our polling request");
+ response = stream2String(method.getResponseBodyAsStream());
+ } catch (IOException e) {
+ throw new MobyException("Problem reading response from webservice",
+ e);
+ } finally {
+ // Release current connection to the connection pool once you
+ // are
+ // done
+ method.releaseConnection();
+ }
+
+ if (response != null) {
+ l_ae = AnalysisEvent.createFromXML(response);
+ }
+
+ if (l_ae == null || l_ae.length == 0) {
+ new MobyException(
+ "Troubles while checking asynchronous MOBY job status from service "
+ + msName);
+ }
+
+ ArrayList<String> finishedQueries = new ArrayList<String>();
+ // Second, gather those finished queries
+ for (int iae = 0; iae < l_ae.length; iae++) {
+ AnalysisEvent ae = l_ae[iae];
+ if (ae.isCompleted()) {
+ String queryId = ae.getQueryId();
+ if (!queryMap.containsKey(queryId)) {
+ throw new MobyException(
+ "Invalid result queryId on asynchronous MOBY job status fetched from "
+ + msName);
+ }
+ finishedQueries.add(queryId);
+ }
+ }
+
+ // Third, let's fetch the results from the finished queries
+ if (finishedQueries.size() > 0) {
+ String[] resQueryIds = finishedQueries.toArray(new String[0]);
+ for (int x = 0; x < resQueryIds.length; x++) {
+ // construct the GetMultipleResourceProperties XML
+ xml = new StringBuffer();
+ xml
+ .append("<wsrf-rp:GetMultipleResourceProperties xmlns:wsrf-rp='"
+ + RESOURCE_PROPERTIES_NS
+ + "' xmlns:mobyws='http://biomoby.org/'>");
+ for (String q : resQueryIds)
+ xml.append("<wsrf-rp:ResourceProperty>mobyws:" + RESULT_PREFIX + q
+ + "</wsrf-rp:ResourceProperty>");
+ xml.append("</wsrf-rp:GetMultipleResourceProperties>");
+
+ httpheader = new StringBuffer();
+ httpheader.append("<moby-wsrf>");
+ httpheader
+ .append("<wsa:Action xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">"
+ + GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION
+ + "</wsa:Action>");
+ httpheader
+ .append("<wsa:To xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsu:Id=\"To\">"
+ + url + "</wsa:To>");
+ httpheader
+ .append("<mobyws:ServiceInvocationId xmlns:mobyws=\"http://biomoby.org/\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter=\"true\">"
+ + epr.getServiceInvocationId()
+ + "</mobyws:ServiceInvocationId>");
+ httpheader.append("</moby-wsrf>");
+ client = new HttpClient();
+ client.getParams().setParameter("http.useragent",
+ "jMoby/Taverna2");
+ // create the post method
+ method = new PostMethod(url + "/results");
+ // add the moby-wsrf header (with no newlines)
+ method.addRequestHeader("moby-wsrf", httpheader.toString()
+ .replaceAll("\r\n", ""));
+
+ // put our data in the request
+ entity = null;
+ try {
+ entity = new StringRequestEntity(xml.toString(),
+ "text/xml", null);
+ } catch (UnsupportedEncodingException e) {
+ throw new MobyException(
+ "Problem posting data to webservice", e);
+ }
+ method.setRequestEntity(entity);
+
+ // retry up to 10 times
+ client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ new DefaultHttpMethodRetryHandler(10, true));
+
+ // call the method
+ try {
+ if (client.executeMethod(method) != HttpStatus.SC_OK)
+ throw new MobyException(
+ "Async HTTP POST service returned code: "
+ + method.getStatusCode() + "\n"
+ + method.getStatusLine()
+ + "\nduring our polling request");
+ // place the result in the array
+ result[x] = stream2String(method.getResponseBodyAsStream());
+ // Marking as null
+ queryIds[x] = null;
+ } catch (IOException e) {
+ logger.warn("Problem getting result from webservice\n"
+ + e.getMessage());
+ } finally {
+ // Release current connection
+ method.releaseConnection();
+ }
+ }
+
+ }
+ return finishedQueries.size() != queryMap.size();
+ }
+
+ private static String stream2String(InputStream is) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
+ String line = null;
+ String newline = System.getProperty("line.separator");
+ try {
+ while ((line = br.readLine()) != null) {
+ sb.append(line + newline);
+ }
+ } catch (IOException e) {
+ logger.warn("Exception reading input stream ...", e);
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ logger.warn("Exception closing input stream ...", e);
+ }
+ }
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncMobyService.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncMobyService.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncMobyService.java
new file mode 100644
index 0000000..10c76bc
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteAsyncMobyService.java
@@ -0,0 +1,695 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.apache.log4j.Logger;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyPrefixResolver;
+import org.biomoby.shared.MobyService;
+import org.biomoby.shared.parser.MobyTags;
+import org.biomoby.w3c.addressing.EndpointReference;
+import org.omg.lsae.notifications.AnalysisEvent;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+
+/**
+ * This class contains one method that is used to execute asynchronous moby
+ * services
+ *
+ * @author Edward Kawas
+ *
+ */
+
+public class ExecuteAsyncMobyService {
+
+ /* async constants */
+ private static final String GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION = "http://docs.oasis-open.org/wsrf/rpw-2/GetMultipleResourceProperties/GetMultipleResourcePropertiesRequest";
+ private static final String DESTROY_RESOURCE_ACTION = "http://docs.oasis-open.org/wsrf/rlw-2/ImmediateResourceTermination/DestroyRequest";
+
+ private static final String RESOURCE_PROPERTIES_NS = "http://docs.oasis-open.org/wsrf/rp-2";
+ private static final String RESOURCE_LIFETIME_NS = "http://docs.oasis-open.org/wsrf/rl-2";
+
+ @SuppressWarnings("unused")
+ private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
+ private static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
+ private static final String WSA_NS = "http://www.w3.org/2005/08/addressing";
+ private static final String WSU_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
+ private static final String ANON_URI = WSA_NS + "/anonymous";
+ private static final String RESULT_PREFIX = "result_";
+ private static final String STATUS_PREFIX = "status_";
+
+ private static Logger logger = Logger.getLogger(ExecuteAsyncMobyService.class);
+ /**
+ * This method does the same as getMultipleResourceProperties, with the
+ * difference that it returns an String instead of a SOAPPart object. The
+ * result is the serialization of the SOAPPart output obtained from
+ * getMultipleResourceProperties.
+ *
+ * @param msName
+ * The MOBY service name
+ * @param queryIds
+ * The array with the queryIds to use. It may contain null
+ * strings
+ * @param epr
+ * The EndpointReference object which helds the MOBY asynchronous
+ * job information
+ * @param asResult
+ * If this parameter is true, then this call fetches the results
+ * associated to the input queryIds. If it is false, then this
+ * call only asks for the job status.
+ * @return When at least one of the strings from queryIds array was not
+ * null, an String with the serialized answer from the service.
+ * Otherwise, it returns null.
+ * @throws SOAPException
+ */
+ private static String getMultipleResourcePropertiesAsString(String msName,
+ String[] queryIds, EndpointReference epr, boolean asResult)
+ throws TransformerConfigurationException, SOAPException,
+ TransformerException {
+ SOAPPart result = getMultipleResourceProperties(msName, queryIds, epr,
+ asResult);
+ if (result == null)
+ return null;
+ Transformer tr = TransformerFactory.newInstance().newTransformer();
+ tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+
+ DOMSource dombody = new DOMSource(result);
+
+ StringWriter sw = new StringWriter();
+ tr.transform(dombody, new StreamResult(sw));
+
+ return sw.toString();
+ }
+
+ /**
+ * This method does the check and fetch work related to asynchronous
+ * services. When all the results are fetched, it returns false. When some
+ * recheck must be issued, it returns true.
+ *
+ * @param msName
+ * The MOBY service name
+ * @param epr
+ * The EndpointReference, used for the queries
+ * @param queryIds
+ * The array which holds the queryIds to ask for. It can contain
+ * null strings.
+ * @param result
+ * The array which will hold the mobyData results. This one must
+ * have the same size as queryIds array.
+ * @return true, if we need more checking iterations. Otherwise, false
+ * @throws MobyException
+ */
+ private static boolean checkMobyAsyncJobsStatus(String msName,
+ EndpointReference epr, String[] queryIds,
+ org.w3c.dom.Element[] result) throws MobyException {
+ // Needed to remap results
+ HashMap<String, Integer> queryMap = new HashMap<String, Integer>();
+ for (int qi = 0; qi < queryIds.length; qi++) {
+ String queryId = queryIds[qi];
+ if (queryId != null)
+ queryMap.put(queryId, new Integer(qi));
+ }
+
+ if (queryMap.size() == 0)
+ return false;
+
+ try {
+ AnalysisEvent[] l_ae = null;
+ // First, status from queries
+ String response = getMultipleResourcePropertiesAsString(msName,
+ queryIds, epr, false);
+ if (response != null) {
+ l_ae = AnalysisEvent.createFromXML(response);
+ }
+
+ if (l_ae == null || l_ae.length == 0) {
+ new MobyException(
+ "Troubles while checking asynchronous MOBY job status from service "
+ + msName);
+ }
+
+ ArrayList<String> finishedQueries = new ArrayList<String>();
+ // Second, gather those finished queries
+ for (int iae = 0; iae < l_ae.length; iae++) {
+ AnalysisEvent ae = l_ae[iae];
+ if (ae.isCompleted()) {
+ String queryId = ae.getQueryId();
+ if (!queryMap.containsKey(queryId)) {
+ throw new MobyException(
+ "Invalid result queryId on asynchronous MOBY job status fetched from "
+ + msName);
+ }
+ finishedQueries.add(queryId);
+ }
+ }
+
+ // Third, let's fetch the results from the finished queries
+ if (finishedQueries.size() > 0) {
+ String[] resQueryIds = finishedQueries.toArray(new String[0]);
+ SOAPPart soapDOM = getMultipleResourceProperties(msName,
+ resQueryIds, epr, true);
+ NodeList l_mul = soapDOM.getElementsByTagNameNS(
+ RESOURCE_PROPERTIES_NS,
+ "GetMultipleResourcePropertiesResponse");
+ if (l_mul == null || l_mul.getLength() == 0) {
+ throw new MobyException(
+ "Error while fetching asynchronous MOBY results from "
+ + msName);
+ }
+
+ org.w3c.dom.Element mul = (org.w3c.dom.Element) l_mul.item(0);
+ for (org.w3c.dom.Node child = mul.getFirstChild(); child != null; child = child
+ .getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && MobyService.BIOMOBY_SERVICE_URI.equals(child
+ .getNamespaceURI())) {
+ String preQueryId = child.getLocalName();
+ int subpos = preQueryId.indexOf(RESULT_PREFIX);
+ if (subpos != 0) {
+ throw new MobyException(
+ "Invalid result prefix on asynchronous MOBY job results fetched from "
+ + msName);
+ }
+ String queryId = preQueryId.substring(RESULT_PREFIX
+ .length());
+ if (!queryMap.containsKey(queryId)) {
+ throw new MobyException(
+ "Invalid result queryId on asynchronous MOBY job results fetched from "
+ + msName);
+ }
+
+ org.w3c.dom.Element elchild = (org.w3c.dom.Element) child;
+ NodeList l_moby = elchild.getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE,
+ MobyTags.MOBYDATA);
+ if (l_moby == null || l_moby.getLength() == 0)
+ l_moby = elchild
+ .getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE_INVALID,
+ MobyTags.MOBYDATA);
+
+ if (l_moby == null || l_moby.getLength() == 0) {
+ throw new MobyException(
+ "Recovered empty payload from asynchronous MOBY service "
+ + msName);
+ }
+ Integer queryPos = queryMap.get(queryId);
+ result[queryPos] = (org.w3c.dom.Element) l_moby.item(0);
+ // Marking as null
+ queryIds[queryPos] = null;
+ }
+ }
+ }
+
+ return finishedQueries.size() != queryMap.size();
+ } catch (SOAPException se) {
+ throw new MobyException("Error while querying MOBY job status", se);
+ } catch (TransformerConfigurationException tce) {
+ throw new MobyException(
+ "Error while preparing to parse MOBY job status", tce);
+ } catch (TransformerException te) {
+ throw new MobyException("Error while parsing MOBY job status", te);
+ }
+ }
+
+ /**
+ * This method calls the input MOBY service using the asynchronous protocol.
+ *
+ * @param endpoint
+ * The endpoint of the service.
+ * @param msName
+ * The MOBY service name.
+ * @param mobyXML
+ * The MOBY payload to be sent to the service.
+ * @return The MOBY payload with the results from the service.
+ * @throws MobyException
+ */
+ public static String executeMobyAsyncService(String endpoint, String msName,
+ String mobyXML) throws MobyException {
+ // First, let's get the queryIds
+ org.w3c.dom.Document message = null;
+
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setValidating(false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ message = db.parse(new InputSource(new StringReader(mobyXML)));
+ } catch (Throwable t) {
+ throw new MobyException("Error while parsing input query", t);
+ }
+
+ NodeList l_data = message.getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE, MobyTags.MOBYDATA);
+ if (l_data == null || l_data.getLength() == 0) {
+ l_data = message.getElementsByTagNameNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE_INVALID,
+ MobyTags.MOBYDATA);
+ }
+
+ // Freeing resources
+ message = null;
+
+ if (l_data == null || l_data.getLength() == 0) {
+ throw new MobyException("Empty asynchronous MOBY query!");
+ }
+
+ int nnode = l_data.getLength();
+ String[] queryIds = new String[nnode];
+ String[] tmpQueryIds = new String[nnode];
+ org.w3c.dom.Element[] results = new org.w3c.dom.Element[nnode];
+ for (int inode = 0; inode < nnode; inode++) {
+ String queryId = null;
+
+ org.w3c.dom.Element mdata = (org.w3c.dom.Element) l_data
+ .item(inode);
+
+ queryId = mdata.getAttribute(MobyTags.QUERYID);
+ if (queryId == null || queryId.length() == 0)
+ queryId = mdata
+ .getAttributeNS(MobyPrefixResolver.MOBY_XML_NAMESPACE,
+ MobyTags.QUERYID);
+ if (queryId == null || queryId.length() == 0)
+ queryId = mdata.getAttributeNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE_INVALID,
+ MobyTags.QUERYID);
+
+ if (queryId == null || queryId.length() == 0) {
+ throw new MobyException(
+ "Unable to extract queryId for outgoing MOBY message");
+ }
+
+ tmpQueryIds[inode] = queryIds[inode] = queryId;
+ results[inode] = null;
+ }
+
+ // Freeing resources
+ l_data = null;
+
+ // Second, let's launch
+ EndpointReference epr = launchMobyAsyncService(endpoint, msName,
+ mobyXML);
+
+ // Third, waiting for the results
+ try {
+ // FIXME - add appropriate values here
+ long pollingInterval = 1000L; // proc.getRetryDelay();
+ double backoff = 1.0;// proc.getBackoff();
+
+ // Max: one minute pollings
+ long maxPollingInterval = 60000L;
+
+ // Min: one second
+ if (pollingInterval <= 0L)
+ pollingInterval = 1000L;
+
+ // Backoff: must be bigger than 1.0
+ if (backoff <= 1.0)
+ backoff = 1.5;
+
+ do {
+ try {
+ Thread.sleep(pollingInterval);
+ } catch (InterruptedException ie) {
+ // DoNothing(R)
+ }
+
+ if (pollingInterval != maxPollingInterval) {
+ pollingInterval = (long) ((double) pollingInterval * backoff/*
+ * proc.
+ * getBackoff
+ * (
+ * )
+ */);
+ if (pollingInterval > maxPollingInterval) {
+ pollingInterval = maxPollingInterval;
+ }
+ }
+ } while (checkMobyAsyncJobsStatus(msName, epr, tmpQueryIds, results));
+ } finally {
+ try {
+ freeAsyncResources(msName, epr);
+ } catch (SOAPException se) {
+ logger.info(
+ "An error was fired while freeing MOBY asynchronous resources from "
+ + msName, se);
+ }
+ }
+
+ // Fourth, assembling back the results
+ org.w3c.dom.Document resdoc = null;
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setValidating(false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ resdoc = db.newDocument();
+
+ org.w3c.dom.Element mobyroot = resdoc.createElementNS(
+ MobyPrefixResolver.MOBY_XML_NAMESPACE, MobyTags.MOBY);
+ resdoc.appendChild(mobyroot);
+ org.w3c.dom.Element mobycontent = resdoc
+ .createElementNS(MobyPrefixResolver.MOBY_XML_NAMESPACE,
+ MobyTags.MOBYCONTENT);
+ mobyroot.appendChild(mobycontent);
+
+ // Results array already contains mobyData
+
+ for (org.w3c.dom.Element result : results) {
+ mobycontent.appendChild(resdoc.importNode(result, true));
+ }
+ } catch (Throwable t) {
+ throw new MobyException("Error while assembling output", t);
+ }
+
+ // Fifth, returning results
+ try {
+ Transformer tr = TransformerFactory.newInstance().newTransformer();
+ tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+
+ DOMSource dombody = new DOMSource(resdoc);
+
+ StringWriter sw = new StringWriter();
+ tr.transform(dombody, new StreamResult(sw));
+
+ return sw.toString();
+ } catch (Throwable t) {
+ throw new MobyException("Error while assembling output", t);
+ }
+ }
+
+ /**
+ * This method free the asynchronous MOBY resources associated to the job
+ * identifier tied to the EndpointReference object passed as input.
+ *
+ * @param msName
+ * The MOBY service name
+ * @param epr
+ * The EndpointReference object which holds the MOBY asynchronous
+ * job information
+ * @throws SOAPException
+ */
+ private static void freeAsyncResources(String msName, EndpointReference epr)
+ throws SOAPException {
+ Service service = Service.create(new QName(
+ MobyService.BIOMOBY_SERVICE_URI, msName + "Service"));
+ QName mQName = new QName(MobyService.BIOMOBY_SERVICE_URI,
+ "WSRF_Operations_Port");
+ service.addPort(mQName, SOAPBinding.SOAP11HTTP_BINDING, epr
+ .getAddress());
+
+ Dispatch<SOAPMessage> dispatch = service.createDispatch(mQName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+ Map<String, Object> rc = dispatch.getRequestContext();
+ rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(true));
+ rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,
+ GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION);
+
+ MessageFactory mf = MessageFactory.newInstance();
+ SOAPMessage request = mf.createMessage();
+ SOAPPart part = request.getSOAPPart();
+
+ String mobyPrefix = "mobyws";
+ String wsaPrefix = "wsa";
+ String wsuPrefix = "wsu";
+ // Obtain the SOAPEnvelope and header and body elements.
+ SOAPEnvelope env = part.getEnvelope();
+ SOAPHeader header = env.getHeader();
+ SOAPBody body = env.getBody();
+
+ header.addNamespaceDeclaration(mobyPrefix,
+ MobyService.BIOMOBY_SERVICE_URI);
+ header.addNamespaceDeclaration(wsaPrefix, WSA_NS);
+ header.addNamespaceDeclaration(wsuPrefix, WSU_NS);
+ // This is for the action
+ SOAPElement actionRoot = header.addChildElement("Action", wsaPrefix,
+ WSA_NS);
+ actionRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS),
+ "Action");
+ actionRoot.addTextNode(DESTROY_RESOURCE_ACTION);
+
+ // This is for the To
+ SOAPElement toRoot = header.addChildElement("To", wsaPrefix, WSA_NS);
+ toRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS), "To");
+ toRoot.addTextNode(epr.getAddress());
+
+ // And this is for the mobyws
+ SOAPElement mobywsRoot = header.addChildElement("ServiceInvocationId",
+ mobyPrefix, MobyService.BIOMOBY_SERVICE_URI);
+ mobywsRoot.addNamespaceDeclaration(wsaPrefix, WSA_NS);
+ mobywsRoot.addAttribute(env.createName("isReferenceParameter",
+ wsaPrefix, WSA_NS), "true");
+ mobywsRoot.addTextNode(epr.getServiceInvocationId());
+
+ // At last, the replyto
+ SOAPElement replyRoot = header.addChildElement("ReplyTo", wsaPrefix,
+ WSA_NS);
+ replyRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS),
+ "ReplyTo");
+ SOAPElement addr = replyRoot.addChildElement("Address", wsaPrefix,
+ WSA_NS);
+ addr.addTextNode(ANON_URI);
+
+ // Let's disable the headers
+ // ((WSBindingProvider)dispatch).setOutboundHeaders(headers);
+
+ // Now the SOAP body
+ body.addChildElement("Destroy", "rl", RESOURCE_LIFETIME_NS);
+
+ request.saveChanges();
+ // We don't mind what it is returned
+ dispatch.invoke(request);
+ }
+
+ /**
+ * This method is used to launch an asynchronous MOBY job.
+ *
+ * @param endpoint
+ * The endpoint of the service.
+ * @param msName
+ * The MOBY service name.
+ * @param mobyXML
+ * The MOBY payload to be sent to the service.
+ * @return The EndpointReference object which helds the details of the MOBY
+ * asynchronous job.
+ * @throws MobyException
+ */
+ private static EndpointReference launchMobyAsyncService(String endpoint,
+ String msName, String mobyXML) throws MobyException {
+ try {
+ Service service = Service.create(new QName(
+ MobyService.BIOMOBY_SERVICE_URI, msName + "Service"));
+ QName mQName = new QName(MobyService.BIOMOBY_SERVICE_URI, msName
+ + "Port");
+
+ service.addPort(mQName, SOAPBinding.SOAP11HTTP_BINDING, endpoint);
+ Dispatch<SOAPMessage> dispatch = service.createDispatch(mQName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+ Map<String, Object> rc = dispatch.getRequestContext();
+ rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(true));
+ rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,
+ MobyService.BIOMOBY_SERVICE_URI + "#" + msName + "_submit");
+
+ MessageFactory mf = MessageFactory.newInstance();
+ SOAPMessage request = mf.createMessage();
+ SOAPPart part = request.getSOAPPart();
+
+ String mobyPrefix = "mobyws";
+ String xsiPrefix = "xsi";
+
+ // Obtain the SOAPEnvelope and header and body elements.
+ SOAPEnvelope env = part.getEnvelope();
+ SOAPBody body = env.getBody();
+
+ // Now the SOAP body
+ body.addNamespaceDeclaration(mobyPrefix,
+ MobyService.BIOMOBY_SERVICE_URI);
+ SOAPElement rootMessage = body.addChildElement(msName + "_submit",
+ mobyPrefix, MobyService.BIOMOBY_SERVICE_URI);
+ SOAPElement data = rootMessage.addChildElement("data", mobyPrefix,
+ MobyService.BIOMOBY_SERVICE_URI);
+ data.addNamespaceDeclaration(xsiPrefix,
+ MobyPrefixResolver.XSI_NAMESPACE2001);
+ data.addNamespaceDeclaration("xsd", XSD_NS);
+ data.addAttribute(env.createName("type", xsiPrefix,
+ MobyPrefixResolver.XSI_NAMESPACE2001), "xsd:string");
+ data.addTextNode(mobyXML);
+
+ request.saveChanges();
+ SOAPMessage outputMessage = dispatch.invoke(request);
+ DOMSource output = new DOMSource(outputMessage.getSOAPPart()
+ .getEnvelope());
+
+ StringWriter sw = new StringWriter();
+ Transformer tr = TransformerFactory.newInstance().newTransformer();
+ tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ tr.transform(output, new StreamResult(sw));
+
+ String response = sw.toString();
+ return EndpointReference.createFromXML(response);
+ } catch (SOAPException pce) {
+ throw new MobyException(
+ "Unable to create SOAP document builder for MOBY asynchronous call submission",
+ pce);
+ } catch (TransformerConfigurationException tce) {
+ throw new MobyException(
+ "Unable to create transformer factory for MOBY asynchronous call response",
+ tce);
+ } catch (TransformerException te) {
+ throw new MobyException(
+ "Unable to create transformer for MOBY asynchronous call response",
+ te);
+ }
+ }
+
+
+
+ /**
+ * This method issues WSRF getMultipleResourceProperties calls. As this call
+ * is used in BioMOBY for polling and for result fetching, it has an
+ * additional parameter which handles the call mode.
+ *
+ * @param msName
+ * The MOBY service name
+ * @param queryIds
+ * The array with the queryIds to use. It may contain null
+ * strings
+ * @param epr
+ * The EndpointReference object which helds the MOBY asynchronous
+ * job information
+ * @param asResult
+ * If this parameter is true, then this call fetches the results
+ * associated to the input queryIds. If it is false, then this
+ * call only asks for the job status.
+ * @return When at least one of the strings from queryIds array was not
+ * null, a SOAPPart object is returned with the answer for the
+ * request issued to the MOBY service. Otherwise, it returns null.
+ * @throws SOAPException
+ */
+ private static SOAPPart getMultipleResourceProperties(String msName,
+ String[] queryIds, EndpointReference epr, boolean asResult)
+ throws SOAPException {
+ String op = asResult ? RESULT_PREFIX : STATUS_PREFIX;
+
+ Service service = Service.create(new QName(
+ MobyService.BIOMOBY_SERVICE_URI, msName + "Service"));
+ QName mQName = new QName(MobyService.BIOMOBY_SERVICE_URI,
+ "WSRF_Operations_Port");
+ service.addPort(mQName, SOAPBinding.SOAP11HTTP_BINDING, epr
+ .getAddress());
+
+ Dispatch<SOAPMessage> dispatch = service.createDispatch(mQName,
+ SOAPMessage.class, Service.Mode.MESSAGE);
+ Map<String, Object> rc = dispatch.getRequestContext();
+ rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(true));
+ rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,
+ GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION);
+
+ MessageFactory mf = MessageFactory.newInstance();
+ SOAPMessage request = mf.createMessage();
+ SOAPPart part = request.getSOAPPart();
+
+ String mobyPrefix = "mobyws";
+ String wsaPrefix = "wsa";
+ String wsuPrefix = "wsu";
+ // Obtain the SOAPEnvelope and header and body elements.
+ SOAPEnvelope env = part.getEnvelope();
+ SOAPHeader header = env.getHeader();
+ SOAPBody body = env.getBody();
+
+ header.addNamespaceDeclaration(mobyPrefix,
+ MobyService.BIOMOBY_SERVICE_URI);
+ header.addNamespaceDeclaration(wsaPrefix, WSA_NS);
+ header.addNamespaceDeclaration(wsuPrefix, WSU_NS);
+ // This is for the action
+ SOAPElement actionRoot = header.addChildElement("Action", wsaPrefix,
+ WSA_NS);
+ actionRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS),
+ "Action");
+ actionRoot.addTextNode(GET_MULTIPLE_RESOURCE_PROPERTIES_ACTION);
+
+ // This is for the To
+ SOAPElement toRoot = header.addChildElement("To", wsaPrefix, WSA_NS);
+ toRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS), "To");
+ toRoot.addTextNode(epr.getAddress());
+
+ // And this is for the mobyws
+ SOAPElement mobywsRoot = header.addChildElement("ServiceInvocationId",
+ mobyPrefix, MobyService.BIOMOBY_SERVICE_URI);
+ mobywsRoot.addNamespaceDeclaration(wsaPrefix, WSA_NS);
+ mobywsRoot.addAttribute(env.createName("isReferenceParameter",
+ wsaPrefix, WSA_NS), "true");
+ mobywsRoot.addTextNode(epr.getServiceInvocationId());
+
+ // At last, the replyto
+ SOAPElement replyRoot = header.addChildElement("ReplyTo", wsaPrefix,
+ WSA_NS);
+ replyRoot.addAttribute(env.createName("Id", wsuPrefix, WSU_NS),
+ "ReplyTo");
+ SOAPElement addr = replyRoot.addChildElement("Address", wsaPrefix,
+ WSA_NS);
+ addr.addTextNode(ANON_URI);
+
+ // Let's disable the headers
+ // ((WSBindingProvider)dispatch).setOutboundHeaders(headers);
+
+ // Now the SOAP body
+ SOAPElement smrp = body.addChildElement(
+ "GetMultipleResourceProperties", "rp", RESOURCE_PROPERTIES_NS);
+ boolean doSubmit = false;
+ for (String queryId : queryIds) {
+ if (queryId != null) {
+ doSubmit = true;
+ SOAPElement sii = smrp.addChildElement("ResourceProperty",
+ "rp", RESOURCE_PROPERTIES_NS);
+ sii.addNamespaceDeclaration(mobyPrefix,
+ MobyService.BIOMOBY_SERVICE_URI);
+ sii.addTextNode(mobyPrefix + ":" + op + queryId);
+ }
+ }
+
+ if (doSubmit) {
+ request.saveChanges();
+ SOAPMessage output = dispatch.invoke(request);
+
+ return output.getSOAPPart();
+ } else {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteCgiService.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteCgiService.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteCgiService.java
new file mode 100644
index 0000000..a221a8a
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteCgiService.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+
+import org.biomoby.shared.MobyException;
+
+/**
+ * This class contains one method that is used to execute synchronous HTTP POST
+ * services
+ *
+ * @author Edward Kawas
+ *
+ */
+
+public class ExecuteCgiService {
+
+ /**
+ *
+ * @param serviceEndpoint
+ * the URL to the HTTP POST service
+ * @param xml
+ * the XML to send the service
+ * @return a string representing the output from the service
+ * @throws MobyException
+ * if anything goes wrong (problems reading/writing to the
+ * service)
+ */
+ public static String executeCgiService(String serviceEndpoint, String xml)
+ throws MobyException {
+ try {
+ // Construct data
+ String data = "data=" + URLEncoder.encode(xml, "UTF-8");
+
+ // Send data
+ URL url = new URL(serviceEndpoint);
+ URLConnection conn = url.openConnection();
+ conn.setDoOutput(true);
+ OutputStreamWriter wr = new OutputStreamWriter(conn
+ .getOutputStream());
+ wr.write(data);
+ wr.flush();
+ // Get the response
+ BufferedReader rd = new BufferedReader(new InputStreamReader(conn
+ .getInputStream()));
+ String line;
+ StringBuffer sb = new StringBuffer();
+ while ((line = rd.readLine()) != null) {
+ sb.append(line);
+ }
+ wr.close();
+ rd.close();
+ return sb.toString();
+ } catch (Exception e) {
+ throw new MobyException(e.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteMobyService.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteMobyService.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteMobyService.java
new file mode 100644
index 0000000..f494d47
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ExecuteMobyService.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.MobyException;
+
+/**
+ * This class contains one method that is used to execute synchronous moby
+ * services
+ *
+ * @author Edward Kawas
+ *
+ */
+
+public class ExecuteMobyService {
+
+ /**
+ *
+ * @param endpoint
+ * the SOAP endpoint of the service to call
+ * @param service
+ * the name of the service
+ * @param xml
+ * the XML to send the service
+ * @return a string of XML representing the output from the service given
+ * our input
+ * @throws MobyException
+ * if anything goes wrong (SOAP error)
+ */
+ public static String executeMobyService(String endpoint, String service,
+ String xml) throws MobyException {
+ return new CentralImpl(endpoint, "http://biomoby.org/").call(service,
+ xml);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/GetOntologyThread.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/GetOntologyThread.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/GetOntologyThread.java
new file mode 100644
index 0000000..e2402e8
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/GetOntologyThread.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+
+package net.sf.taverna.t2.activities.biomoby;
+
+
+import org.biomoby.client.CentralImpl;
+
+/**
+ * This class is used to speed up the running of workflows. Basically, whenever
+ * a new Biomoby activity is added to taverna, a call out to RESOURCES/Objects
+ * is made to download the datatype ontology.
+ *
+ * Uses BiomobyCache to process the registry
+ *
+ * This should speed up the execution of workflows, since the ontologies will
+ * have already been downloaded.
+ *
+ * @author Eddie Kawas
+ * @author Stuart Owen
+ *
+ * @see BiomobyCache
+ *
+ */
+public class GetOntologyThread extends Thread {
+
+
+ // the registry endpoint
+ String worker = null;
+
+ /**
+ *
+ * @param url
+ * the registry endpoint URL
+ */
+ public GetOntologyThread(String url) {
+ super("BioMOBY GetOntologyThread");
+ if (url == null || url.trim().equals(""))
+ url = CentralImpl.getDefaultURL();
+ this.worker = url;
+ setDaemon(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Thread#run()
+ */
+ public void run() {
+ BiomobyCache.cacheForRegistryEndpoint(worker);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java
new file mode 100644
index 0000000..c33a5bf
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java
@@ -0,0 +1,417 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+
+import net.sf.taverna.t2.annotation.annotationbeans.MimeType;
+import net.sf.taverna.t2.reference.ExternalReferenceSPI;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.EditException;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AbstractAsynchronousActivity;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityConfigurationException;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+import org.biomoby.client.CentralImpl;
+import org.biomoby.shared.Central;
+import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.MobyException;
+import org.biomoby.shared.MobyRelationship;
+import org.biomoby.shared.NoSuccessException;
+
+/**
+ * An Activity that breaks up a Moby datatype into its component parts minus all
+ * the moby wrappings.
+ *
+ * Copied from org.biomoby.client.taverna.plugin.MobyParseDatatypeActivityProcessor and
+ * org.biomoby.client.taverna.plugin.MobyParseDatatypeActivityTask and converted to a Taverna 2
+ * Activity.
+ *
+ * @author Edward Kawas
+ * @author David Withers
+ */
+public class MobyParseDatatypeActivity extends AbstractAsynchronousActivity<MobyParseDatatypeActivityConfigurationBean> {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/biomoby/parser";
+
+ private static Logger logger = Logger.getLogger(MobyParseDatatypeActivity.class);
+
+ private MobyParseDatatypeActivityConfigurationBean configurationBean = new MobyParseDatatypeActivityConfigurationBean();
+
+ private Central central = null;
+
+ private MobyDataType datatype = null;
+
+ @Override
+ public void configure(MobyParseDatatypeActivityConfigurationBean configurationBean) throws ActivityConfigurationException {
+ this.configurationBean = configurationBean;
+ init();
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ @SuppressWarnings("unchecked")
+ public void run() {
+ ReferenceService referenceService = callback.getContext().getReferenceService();
+
+ Map<String, T2Reference> output = new HashMap<String, T2Reference>();
+
+ try {
+
+ //cache ontology and namespace if not done so already. Immediately returns if already cached.
+ BiomobyCache.cacheForRegistryEndpoint(getConfiguration().getRegistryEndpoint());
+
+ String inputMapKey = getInputPorts().iterator().next().getName();
+ // inputMap wasnt as expected
+ if (!data.containsKey(inputMapKey)) {
+ callback.receiveResult(output, new int[0]);
+ return;
+ }
+
+ T2Reference inputId = data.get(inputMapKey);
+
+ Object input = referenceService.renderIdentifier(inputId, String.class, callback.getContext());
+
+ if (input instanceof String) {
+ //logger.error(inputMapKey + " is a string!\n");
+ String inputXML = (String) input;
+ for (OutputPort outPort : getOutputPorts()) {
+ String outputPortName = outPort.getName();
+ String[] invocations = XMLUtilities.getSingleInvokationsFromMultipleInvokations(inputXML);
+ ArrayList<String> names = new ArrayList<String>();
+ int type = 0;
+ // get the type, names list, etc
+ if (outputPortName.equalsIgnoreCase("namespace")) {
+ // extract the namespace from the top element
+ names.add(configurationBean.getArticleNameUsedByService());
+ type = ParseMobyXML.NAMESPACE;
+ } else if (outputPortName.equalsIgnoreCase("id")) {
+ // extract the id from the top element
+ names.add(configurationBean.getArticleNameUsedByService());
+ type = ParseMobyXML.ID;
+ } else {
+ names = getNames(outputPortName);
+ if (outputPortName.endsWith("_ns")) {
+ type = ParseMobyXML.NAMESPACE;
+ if (names.size() > 1) // added nov15-2007
+ names.remove(names.size()-1);
+ } else if (outputPortName.endsWith("_id")) {
+ type = ParseMobyXML.ID;
+ if (names.size() > 1)//added nov15-2007
+ names.remove(names.size()-1);
+ } else {
+ type = ParseMobyXML.VALUE;
+ }
+ }
+ ArrayList<String> stuff = new ArrayList<String>();
+ for (int i = 0; i < invocations.length; i++) {
+ String invocation = invocations[i];
+ if (XMLUtilities.isCollection(invocation)) {
+ String[] simples = XMLUtilities.getAllSimplesByArticleName(configurationBean.getArticleNameUsedByService(), invocation);
+ for (int j = 0; j < simples.length; j++) {
+ ArrayList<String> content = ParseMobyXML.getContentForDataType(names, type, XMLUtilities.createMobyDataElementWrapper(simples[j],"a1", null), configurationBean.getRegistryEndpoint());
+ stuff.addAll(content);
+ }
+ } else {
+ ArrayList<String> content = ParseMobyXML.getContentForDataType(names, type, invocations[i],configurationBean.getRegistryEndpoint());
+ stuff.addAll(content);
+ }
+ }
+ output.put(outputPortName, referenceService.register(stuff, 1, true, callback.getContext()));
+ }
+
+ } else if (input instanceof List) {
+ //logger.error(inputMapKey + " is a list!\n");
+ List<String> list = (List) input;
+ // holder contains a list of strings indexed by output port name
+ // TODO put stuff in the map and in the end put it in the output map
+ HashMap<String, ArrayList<String>> holder = new HashMap<String, ArrayList<String>>();
+ for (Iterator<String> it = list.iterator(); it.hasNext();) {
+ String inputXML = (String) it.next();
+ for (OutputPort outPort : getOutputPorts()) {
+ String outputPortName = outPort.getName();
+ String[] invocations = XMLUtilities.getSingleInvokationsFromMultipleInvokations(inputXML);
+ ArrayList<String> names = new ArrayList<String>();
+ int type = 0;
+ // get the type, names list, etc
+ if (outputPortName.equalsIgnoreCase("namespace")) {
+ // extract the namespace from the top element
+ names.add(configurationBean.getArticleNameUsedByService());
+ type = ParseMobyXML.NAMESPACE;
+ } else if (outputPortName.equalsIgnoreCase("id")) {
+ // extract the id from the top element
+ names.add(configurationBean.getArticleNameUsedByService());
+ type = ParseMobyXML.ID;
+ } else {
+ names = getNames(outputPortName);
+ if (outputPortName.endsWith("_ns")) {
+ type = ParseMobyXML.NAMESPACE;
+ if (names.size() > 1)//added nov-15-07
+ names.remove(names.size()-1);
+ } else if (outputPortName.endsWith("_id")) {
+ type = ParseMobyXML.ID;
+ if (names.size() > 1)//added nov-15-07
+ names.remove(names.size()-1);
+ } else {
+ type = ParseMobyXML.VALUE;
+ }
+ }
+ ArrayList<String> stuff = new ArrayList<String>();
+ for (int i = 0; i < invocations.length; i++) {
+ String invocation = invocations[i];
+ if (XMLUtilities.isCollection(invocation)) {
+ String[] simples = XMLUtilities.getAllSimplesByArticleName(configurationBean.getArticleNameUsedByService(), invocation);
+ for (int j = 0; j < simples.length; j++) {
+ ArrayList<String> content = ParseMobyXML.getContentForDataType(names, type, XMLUtilities.createMobyDataElementWrapper(simples[j],"a1", null),configurationBean.getRegistryEndpoint());
+ stuff.addAll(content);
+ }
+ } else {
+ ArrayList<String> content = ParseMobyXML.getContentForDataType(names, type, invocations[i],configurationBean.getRegistryEndpoint());
+ stuff.addAll(content);
+ }
+ }
+ if (holder.containsKey(outputPortName)) {
+ ArrayList<String> al = holder.get(outputPortName);
+ al.addAll(stuff);
+ holder.put(outputPortName, al);
+ } else {
+ holder.put(outputPortName, stuff);
+ }
+ }
+ }
+ // fill output map
+ for (Iterator<String> it = holder.keySet().iterator(); it.hasNext();) {
+ String key = it.next();
+ output.put(key, referenceService.register(holder.get(key), 1, true, callback.getContext()));
+ }
+ }
+
+ callback.receiveResult(output, new int[0]);
+ } catch (ReferenceServiceException e) {
+ callback.fail("Error accessing input/output data", e);
+ } catch (Exception e) {
+ callback.fail("rror parsing moby data", e);
+ }
+
+ }
+ });
+ }
+
+ @Override
+ public MobyParseDatatypeActivityConfigurationBean getConfiguration() {
+ return configurationBean;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void init() throws ActivityConfigurationException {
+ try {
+ central = new CentralImpl(configurationBean.getRegistryEndpoint());
+ } catch (MobyException e) {
+ throw new ActivityConfigurationException("Couldn't create MobyCentral client for endpoint "
+ + configurationBean.getRegistryEndpoint() + System.getProperty("line.separator")
+ + e.getLocalizedMessage());
+ }
+ if (this.datatype == null) {
+ try {
+ this.datatype = central.getDataType(configurationBean.getDatatypeName());
+ } catch (MobyException e) {
+ throw new ActivityConfigurationException(
+ "There was a problem getting information from the MobyCentral registry at "
+ + configurationBean.getRegistryEndpoint() + System.getProperty("line.separator")
+ + e.getLocalizedMessage());
+ } catch (NoSuccessException e) {
+ throw new ActivityConfigurationException(
+ "There was no success in getting information from the MobyCentral registry at "
+ + configurationBean.getRegistryEndpoint() + System.getProperty("line.separator")
+ + e.getLocalizedMessage());
+ }
+ }
+
+// setDescription("Service to parse the datatype " + this.datatype.getName());
+
+ ArrayList list = new ArrayList();
+ if (isPrimitive(this.datatype.getName())) {
+ list.add(configurationBean.getArticleNameUsedByService() + "_" + this.datatype.getName());
+ } else if (this.datatype.getName().equals("Object")) {
+ // dont do anything because object has no value
+ } else {
+ processDatatype(this.datatype, central, configurationBean.getArticleNameUsedByService(), list);
+ }
+ // add the input port called mobyData('datatypeName')
+ addInput("mobyData('" + this.datatype.getName() + "')", 0, true,
+ new ArrayList<Class<? extends ExternalReferenceSPI>>(),
+ String.class);
+ // add the namespace/id ports to the processor
+ addOutput("namespace", 1, "text/xml");
+ addOutput("id", 1, "text/xml");
+
+ // list contains the output ports i have to create
+ for (Iterator it = list.iterator(); it.hasNext();) {
+ String portName = (String) it.next();
+ if (portName.equals(configurationBean.getArticleNameUsedByService()+"_id") || portName.equals(configurationBean.getArticleNameUsedByService()+"_ns"))
+ continue;
+ addOutput(portName, 1, "text/xml");
+ }
+ }
+
+ private boolean isPrimitive(String name) {
+ if (name.equals("Integer") || name.equals("String") || name.equals("Float")
+ || name.equals("DateTime") || name.equals("Boolean")
+ )
+ return true;
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void processDatatype(MobyDataType dt, Central central, String currentName, List list) throws ActivityConfigurationException {
+
+ if (dt.getParentName() == null || dt.getParentName().trim().equals("")) {
+ //TODO should we throw an error or just return ...
+ return;
+ }
+
+ if (!dt.getParentName().equals("Object")) {
+ flattenChildType(dt.getParentName(), central, currentName, list);
+ } else {
+ list.add(currentName + "_id");
+ list.add(currentName + "_ns");
+ }
+
+ MobyRelationship[] relations = dt.getChildren();
+ for (int i = 0; i < relations.length; i++) {
+ MobyRelationship relation = relations[i];
+ switch (relation.getRelationshipType()) {
+ case CentralImpl.iHAS: {
+ // check for object or primitives
+ if (isPrimitive(relation.getDataTypeName()) || relation.getDataTypeName().equals("Object")) {
+ // object has no value ... only primitives do
+ if (!relation.getDataTypeName().equals("Object"))
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName() + (currentName.equals("") ? "" : "'"));
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName() + (currentName.equals("") ? "" : "'")+"_id");
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName() + (currentName.equals("") ? "" : "'")+"_ns");
+ }
+ else {
+ flattenChildType(relation.getDataTypeName(), central, currentName
+ + (currentName.equals("") ? "" : "_'") + relation.getName() + (currentName.equals("") ? "" : "'"), list);
+ }
+ }
+ break;
+ case CentralImpl.iHASA: {
+ // check for object or primitives ...
+ if (isPrimitive(relation.getDataTypeName()) || relation.getDataTypeName().equals("Object")) {
+ // object has no value ... only primitives do
+ if (!relation.getDataTypeName().equals("Object"))
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName()+ (currentName.equals("") ? "" : "'"));
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName() + (currentName.equals("") ? "" : "'")+"_id");
+ list.add(currentName + (currentName.equals("") ? "" : "_'")
+ + relation.getName() + (currentName.equals("") ? "" : "'")+"_ns");
+ }
+ else {
+
+ flattenChildType(relation.getDataTypeName(), central, currentName
+ + (currentName.equals("") ? "" : "_'") + relation.getName() + (currentName.equals("") ? "" : "'"), list);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private void flattenChildType(String name, Central central, String current, List list) throws ActivityConfigurationException {
+ MobyDataType dt = null;
+ try {
+ dt = central.getDataType(name);
+ } catch (MobyException e) {
+ throw new ActivityConfigurationException(
+ "There was a problem getting information from the MobyCentral registry at "
+ + configurationBean.getRegistryEndpoint() + System.getProperty("line.separator")
+ + e.getLocalizedMessage());
+ } catch (NoSuccessException e) {
+ throw new ActivityConfigurationException(
+ "There was no success in getting information from the MobyCentral registry at "
+ + configurationBean.getRegistryEndpoint() + System.getProperty("line.separator")
+ + e.getLocalizedMessage());
+ }
+ processDatatype(dt, central, current, list);
+ }
+
+ private ArrayList<String> getNames(String names) {
+ ArrayList<String> list = new ArrayList<String>();
+ ArrayList<String> temp = new ArrayList<String>();
+ if (names == null || names.trim().length() == 0)
+ return list;
+ Scanner s = new Scanner(names).useDelimiter("_'");
+ while (s.hasNext()) {
+ temp.add(s.next());
+ }
+ s.close();
+
+ for (String str : temp) {
+ if (str.indexOf("'_") >= 0) {
+ String[] strings = str.split("'_");
+ for (int i = 0; i < strings.length; i++) {
+ list.add(strings[i].replaceAll("'", ""));
+ }
+ } else {
+ list.add(str.replaceAll("'", ""));
+ }
+ }
+
+ if (list.size() == 1) {
+ if (endsWithPrimitive(list.get(0))) {
+ String name = list.remove(0);
+ int i = name.lastIndexOf("_");
+ name = name.substring(0, i);
+ list.add(name);
+ }
+ } else if (isPrimitive(list.get(list.size()-1))) {
+ // remove the last entry if its a primitive ... legacy reasons
+ list.remove(list.size()-1);
+ }
+ return list;
+ }
+
+ private static boolean endsWithPrimitive(String name) {
+ if (name.endsWith("_Integer") || name.endsWith("_String") || name.endsWith("_Float")
+ || name.endsWith("_DateTime") || name.endsWith("_Boolean"))
+ return true;
+ return false;
+ }
+
+ protected void addOutput(String portName, int portDepth, String type) {
+ OutputPort port = edits.createActivityOutputPort(
+ portName, portDepth, portDepth);
+ MimeType mimeType = new MimeType();
+ mimeType.setText(type);
+ try {
+ edits.getAddAnnotationChainEdit(port, mimeType).doEdit();
+ } catch (EditException e) {
+ logger.debug("Error adding MimeType annotation to port", e);
+ }
+ outputPorts.add(port);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java
new file mode 100644
index 0000000..1f02e7e
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A configuration bean specific to the Moby Parse Datatype activity.
+ *
+ * @author David Withers
+ */
+@ConfigurationBean(uri = MobyParseDatatypeActivity.URI + "#Config")
+public class MobyParseDatatypeActivityConfigurationBean {
+
+ private String datatypeName="";
+
+ private String registryEndpoint="";
+
+ private String articleNameUsedByService="";
+
+ /**
+ * Returns the datatypeName.
+ *
+ * @return the datatypeName
+ */
+ public String getDatatypeName() {
+ return datatypeName;
+ }
+
+ /**
+ * Sets the datatypeName.
+ *
+ * @param datatypeName the new datatypeName
+ */
+ @ConfigurationProperty(name = "datatypeName", label = "Datatype Name", description = "")
+ public void setDatatypeName(String datatypeName) {
+ this.datatypeName = datatypeName;
+ }
+
+ /**
+ * Returns the registryEndpoint.
+ *
+ * @return the registryEndpoint
+ */
+ public String getRegistryEndpoint() {
+ return registryEndpoint;
+ }
+
+ /**
+ * Sets the registryEndpoint.
+ *
+ * @param registryEndpoint the new registryEndpoint
+ */
+ @ConfigurationProperty(name = "registryEndpoint", label = "Registry Endpoint", description = "")
+ public void setRegistryEndpoint(String registryEndpoint) {
+ this.registryEndpoint = registryEndpoint;
+ }
+
+ /**
+ * Returns the articleNameUsedByService.
+ *
+ * @return the articleNameUsedByService
+ */
+ public String getArticleNameUsedByService() {
+ return articleNameUsedByService;
+ }
+
+ /**
+ * Sets the articleNameUsedByService.
+ *
+ * @param articleNameUsedByService the new articleNameUsedByService
+ */
+ @ConfigurationProperty(name = "articleNameUsedByService", label = "Article Name Used By Service", description = "")
+ public void setArticleNameUsedByService(String articleNameUsedByService) {
+ this.articleNameUsedByService = articleNameUsedByService;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java
new file mode 100644
index 0000000..8da531e
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (C) 2011 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.net.URI;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+
+/**
+ * An {@link ActivityFactory} for creating <code>MobyParseDatatypeActivity</code>.
+ *
+ * @author David Withers
+ */
+public class MobyParseDatatypeActivityFactory implements ActivityFactory {
+
+ @Override
+ public MobyParseDatatypeActivity createActivity() {
+ return new MobyParseDatatypeActivity();
+ }
+
+ @Override
+ public URI getActivityURI() {
+ return URI.create(MobyParseDatatypeActivity.URI);
+ }
+
+ @Override
+ public Object createActivityConfiguration() {
+ return new MobyParseDatatypeActivityConfigurationBean();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java
new file mode 100644
index 0000000..0ca0d38
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * This file is a component of the Taverna project, and is licensed under the
+ * GNU LGPL. Copyright Edward Kawas, The BioMoby Project
+ ******************************************************************************/
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.processor.activity.Activity;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+
+import net.sf.taverna.t2.workflowmodel.health.RemoteHealthChecker;
+import net.sf.taverna.t2.workflowmodel.processor.activity.DisabledActivity;
+
+
+/**
+ * A health checker for the Moby Parse Datatype activity.
+ *
+ * @author David Withers
+ */
+public class MobyParseDatatypeActivityHealthChecker extends RemoteHealthChecker {
+
+
+ public boolean canVisit(Object subject) {
+ if (subject == null) {
+ return false;
+ }
+ if (subject instanceof MobyParseDatatypeActivity) {
+ return true;
+ }
+ if (subject instanceof DisabledActivity) {
+ return (((DisabledActivity) subject).getActivity() instanceof MobyParseDatatypeActivity);
+ }
+ return false;
+ }
+
+ public VisitReport visit(Object o, List<Object> ancestors) {
+ Activity activity = (Activity) o;
+ MobyParseDatatypeActivityConfigurationBean configuration = null;
+ if (activity instanceof MobyParseDatatypeActivity) {
+ configuration = (MobyParseDatatypeActivityConfigurationBean) activity.getConfiguration();
+ } else if (activity instanceof DisabledActivity) {
+ configuration = (MobyParseDatatypeActivityConfigurationBean) ((DisabledActivity) activity).getActivityConfiguration();
+ }
+ return contactEndpoint(activity, configuration.getRegistryEndpoint());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java
----------------------------------------------------------------------
diff --git a/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java
new file mode 100644
index 0000000..042b6e8
--- /dev/null
+++ b/taverna-biomoby-activity/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java
@@ -0,0 +1,192 @@
+/*
+ * This file is a component of the Taverna project,
+ * and is licensed under the GNU LGPL.
+ * Copyright Edward Kawas, The BioMoby Project
+ */
+package net.sf.taverna.t2.activities.biomoby;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.data.MobyContentInstance;
+import org.biomoby.shared.data.MobyDataBoolean;
+import org.biomoby.shared.data.MobyDataComposite;
+import org.biomoby.shared.data.MobyDataFloat;
+import org.biomoby.shared.data.MobyDataInstance;
+import org.biomoby.shared.data.MobyDataInt;
+import org.biomoby.shared.data.MobyDataJob;
+import org.biomoby.shared.data.MobyDataObject;
+import org.biomoby.shared.data.MobyDataObjectVector;
+import org.biomoby.shared.data.MobyDataString;
+import org.biomoby.shared.data.MobyDataUtils;
+import org.biomoby.registry.meta.Registry;
+
+/**
+ * This class is used to help parse BioMOBY messages.
+ *
+ * @author Edward Kawas
+ *
+ */
+public class ParseMobyXML {
+
+ private static Logger logger = Logger.getLogger(ParseMobyXML.class);
+
+ public static final int NAMESPACE = -10;
+
+ public static final int ID = -20;
+
+ public static final int VALUE = -30;
+
+ private static final List<Integer> allowables;
+
+ static {
+ allowables = new ArrayList<Integer>();
+ allowables.add(NAMESPACE);
+ allowables.add(ID);
+ allowables.add(VALUE);
+ }
+
+ /**
+ * PRECONDITION: XML is valid MOBY xml and contains exactly 1 invocation
+ * message containing our simple element
+ *
+ * @param names
+ * an array of article names in the order that we will
+ * extract our information
+ * @param type
+ * one of {NAMESPACE | ID | VALUE} denoting what exactly it
+ * is that you would like returned
+ * @param xml
+ * the MOBY xml containing the data to extract
+ * @param endpoint
+ * the BioMOBY registry endpoint to use
+ * @return a list of strings representing what it is you asked for
+ */
+ public static ArrayList<String> getContentForDataType(
+ ArrayList<String> names, int type, String xml, String endpoint) {
+ if (!allowables.contains(type) || names == null || names.size() == 0
+ || xml == null || xml.trim().length() == 0) {
+ // nothing to return
+ logger.warn("Parser invoked on an empty message ...");
+ return new ArrayList<String>();
+ }
+ MobyContentInstance contents;
+ try {
+ contents = MobyDataUtils.fromXMLDocument(new ByteArrayInputStream(
+ xml.getBytes("UTF8")), new Registry(endpoint, endpoint,
+ "http://domain.com/MOBY/Central"));
+ } catch (Exception e) {
+ logger.error("There was a problem parsing the input XML:\n" + xml
+ + "\n", e);
+ return new ArrayList<String>();
+ }
+ if (contents.keySet().size() != 1) {
+ return new ArrayList<String>();
+ }
+
+ ArrayList<String> clone = new ArrayList<String>();
+ clone.addAll(names);
+ ArrayList<String> output = new ArrayList<String>();
+ // should be exactly 1 job!
+ Iterator<String> jobIDs = contents.keySet().iterator();
+ while (jobIDs.hasNext()) {
+ MobyDataJob job = (MobyDataJob) contents.get(jobIDs.next());
+ // get the instance
+ MobyDataInstance data = job.get(clone.remove(0));
+ if (data == null)
+ return output;
+ recurse(clone, data, output, type);
+ }
+ return output;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void recurse(ArrayList<String> names, MobyDataInstance data,
+ ArrayList<String> output, int type) {
+ // base case => we have finally found the element of interest
+ if (names.isEmpty()) {
+ baseCase(data, output, type);
+ return;
+ }
+ if (data instanceof MobyDataObjectVector) {
+ // recurse on the children -- the recursion will extract by
+ // articlename
+ MobyDataObjectVector vector = (MobyDataObjectVector) data;
+ // recurse on the has relationship
+ for (Iterator i = vector.iterator(); i.hasNext();) {
+ recurse((ArrayList) (names.clone()), (MobyDataInstance) i
+ .next(), output, type);
+ }
+
+ } else if (data instanceof MobyDataComposite) {
+ // recurse on the child given by name.get(0)
+ MobyDataInstance d = ((MobyDataComposite) data).remove(names
+ .remove(0));
+ recurse((ArrayList) (names.clone()), d, output, type);
+ } else if (data instanceof MobyDataBoolean) {
+ baseCase(data, output, type);
+ } else if (data instanceof MobyDataFloat) {
+ baseCase(data, output, type);
+ } else if (data instanceof MobyDataInt) {
+ baseCase(data, output, type);
+ } else if (data instanceof MobyDataString) {
+ baseCase(data, output, type);
+ }
+
+ }
+
+ private static void baseCase(MobyDataInstance data,
+ ArrayList<String> output, int type) {
+ if (data == null)
+ return;
+ switch (type) {
+ case NAMESPACE: {
+ if (data instanceof MobyDataObjectVector) {
+ MobyDataObjectVector vector = (MobyDataObjectVector) data;
+ for (Iterator i = vector.iterator(); i.hasNext();) {
+ MobyNamespace[] namespaces = ((MobyDataObject) i.next())
+ .getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ output.add(namespaces[j].getName());
+ }
+ }
+ } else {
+ MobyNamespace[] namespaces = ((MobyDataObject) data)
+ .getNamespaces();
+ for (int j = 0; j < namespaces.length; j++) {
+ output.add(namespaces[j].getName());
+ }
+ }
+ }
+ break;
+ case ID: {
+ if (data instanceof MobyDataObjectVector) {
+ MobyDataObjectVector vector = (MobyDataObjectVector) data;
+ for (Iterator i = vector.iterator(); i.hasNext();) {
+ output.add(((MobyDataObject) i.next()).getId());
+ }
+ } else {
+ output.add(((MobyDataObject) data).getId());
+ }
+ }
+ break;
+ case VALUE: {
+ if (data instanceof MobyDataObjectVector) {
+ MobyDataObjectVector vector = (MobyDataObjectVector) data;
+ for (Iterator i = vector.iterator(); i.hasNext();) {
+ output.add(((MobyDataObject) i.next()).getValue());
+ }
+ } else {
+ output.add(((MobyDataObject) data).getValue());
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
[14/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartService.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartService.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartService.java
new file mode 100644
index 0000000..c02bbb5
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartService.java
@@ -0,0 +1,709 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartService.java,v $errors/failure.html
+ * Revision $Revision: 1.7 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/08/11 12:48:29 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import org.apache.log4j.Logger;
+import org.biomart.martservice.query.Query;
+import org.ensembl.mart.lib.config.ConfigurationException;
+import org.ensembl.mart.lib.config.DatasetConfig;
+import org.ensembl.mart.lib.config.DatasetConfigXMLUtils;
+import org.ensembl.mart.lib.config.Exportable;
+import org.ensembl.mart.lib.config.Importable;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.xml.sax.InputSource;
+
+/**
+ * A class for interacting with a BioMart web service.
+ *
+ * @author David Withers
+ */
+public class MartService {
+ private static Logger logger = Logger.getLogger(MartServiceUtils.class);
+
+ private String location;
+
+ private String requestId;
+
+ private File cacheDirectory;
+
+ private MartRegistry registry;
+
+ private Map<MartURLLocation, String> versionMap = new HashMap<MartURLLocation, String>();
+
+ private Map<String, MartDataset[]> datasetsMap = new HashMap<String, MartDataset[]>();
+
+ private Map<String, SoftReference<DatasetConfig>> datasetConfigMap = new HashMap<String, SoftReference<DatasetConfig>>();
+
+ private Map<String, Importable[]> importablesMap = new HashMap<String, Importable[]>();
+
+ private Map<String, Exportable[]> exportablesMap = new HashMap<String, Exportable[]>();
+
+ private Map<MartDataset, List<DatasetLink>> linkableDatasetsMap = new HashMap<MartDataset, List<DatasetLink>>();
+
+ private Map<MartDataset, Set<DatasetLink>> datasetToLinkSetMap = new HashMap<MartDataset, Set<DatasetLink>>();
+
+ private Map<MartDataset, Map<MartDataset, MartDataset>> datasetsToPathMap = new HashMap<MartDataset, Map<MartDataset, MartDataset>>();
+
+ private static final Map<String, MartService> martServiceMap = new HashMap<String, MartService>();
+
+ private static final String fs = System.getProperty("file.separator");
+
+ private boolean linksCalculated = false;
+
+ /**
+ * Constructs an instance of a <code>MartService</code> with the specified
+ * location.
+ *
+ * The location must be the URL of a valid BioMart MartService, e.g.
+ * http://www.biomart.org/biomart/martservice
+ *
+ * @param location
+ * the URL of the MartService
+ */
+ private MartService(String location) {
+ this.location = location;
+ }
+
+ /**
+ * Returns a <code>MartService</code> for the specified location. If a
+ * <code>MartService</code> does not exist for the location a new one is
+ * constructed.
+ *
+ * The location must be the URL of a valid BioMart MartService, e.g.
+ * http://www.biomart.org/biomart/martservice
+ *
+ * @param location
+ * the URL of the MartService
+ */
+ public static MartService getMartService(String location) {
+ if (!martServiceMap.containsKey(location)) {
+ martServiceMap.put(location, new MartService(location));
+ }
+ return martServiceMap.get(location);
+ }
+
+ /**
+ * Returns the requestId.
+ *
+ * @return the requestId
+ */
+ public String getRequestId() {
+ return requestId;
+ }
+
+ /**
+ * Sets the requestId.
+ *
+ * @param requestId
+ * the new requestId
+ */
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+
+ /**
+ * Returns the cacheDirectory.
+ *
+ * @return the cacheDirectory
+ */
+ public File getCacheDirectory() {
+ return cacheDirectory;
+ }
+
+ /**
+ * Sets the cacheDirectory.
+ *
+ * @param cacheDirectory
+ * the new cacheDirectory
+ */
+ public void setCacheDirectory(File cacheDirectory) {
+ this.cacheDirectory = cacheDirectory;
+ }
+
+ /**
+ * Returns the URL of the MartService.
+ *
+ * @return the URL of the MartService
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /**
+ * Removes any cached items.
+ */
+ public void clearCache() {
+ registry = null;
+ datasetsMap.clear();
+ datasetConfigMap.clear();
+ importablesMap.clear();
+ exportablesMap.clear();
+ }
+
+ /**
+ * Returns the MartRegistry for this MartService.
+ *
+ * @return the MartRegistry for this MartService
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public MartRegistry getRegistry() throws MartServiceException {
+ if (registry == null) {
+ registry = MartServiceUtils.getRegistry(location, requestId);
+ }
+ return registry;
+ }
+
+ public String getVersion(MartURLLocation martURLLocation)
+ throws MartServiceException {
+ if (!versionMap.containsKey(martURLLocation)) {
+ versionMap.put(martURLLocation, MartServiceUtils.getVersion(
+ location, requestId, martURLLocation));
+ }
+ return versionMap.get(martURLLocation);
+ }
+
+ /**
+ * Returns all the datasets available from this MartService.
+ *
+ * @return all the datasets available from this MartService.
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public MartDataset[] getDatasets() throws MartServiceException {
+ List<MartDataset> datasets = new ArrayList<MartDataset>();
+ MartURLLocation[] locations = getRegistry().getMartURLLocations();
+ for (int i = 0; i < locations.length; i++) {
+ datasets.addAll(Arrays.asList(getDatasets(locations[i])));
+ }
+ return datasets.toArray(new MartDataset[datasets.size()]);
+ }
+
+ /**
+ * Returns the datasets belonging to the virtualSchema.
+ *
+ * @param virtualSchema
+ * the virtual schema to include datasets from.
+ * @return the datasets belonging to the virtualSchema.
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public MartDataset[] getDatasets(String virtualSchema)
+ throws MartServiceException {
+ List<MartDataset> datasets = new ArrayList<MartDataset>();
+ MartURLLocation[] locations = getRegistry().getMartURLLocations();
+ for (int i = 0; i < locations.length; i++) {
+ if (virtualSchema == null
+ || virtualSchema.equals(locations[i].getVirtualSchema())) {
+ datasets.addAll(Arrays.asList(getDatasets(locations[i])));
+ }
+ }
+ return datasets.toArray(new MartDataset[datasets.size()]);
+ }
+
+ /**
+ * Returns the datasets specified by martURLLocation.
+ *
+ * @param martURLLocation
+ * where to find the datasets.
+ * @return the datasets specified by martURLLocation.
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public MartDataset[] getDatasets(MartURLLocation martURLLocation)
+ throws MartServiceException {
+ String name = martURLLocation.getName();
+ if (!datasetsMap.containsKey(name)) {
+ datasetsMap.put(name, MartServiceUtils.getDatasets(location,
+ requestId, martURLLocation));
+ }
+ return datasetsMap.get(name);
+ }
+
+ /**
+ * Returns the dataset specified by a virtualSchema and a dataset name.
+ *
+ * @param virtualSchema
+ * the virtualSchema containing the dataset
+ * @param datasetName
+ * the name of the dataset to return
+ * @return a dataset
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public MartDataset getDataset(String virtualSchema, String datasetName)
+ throws MartServiceException {
+ MartDataset result = null;
+ MartDataset[] datasets = getDatasets(virtualSchema);
+ for (int i = 0; i < datasets.length; i++) {
+ if (datasetName.equals(datasets[i].getName())) {
+ result = datasets[i];
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns the configuration for a dataset.
+ *
+ * @param dataset
+ * the dataset to get the configuration for
+ * @return the configuration for a dataset
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public DatasetConfig getDatasetConfig(MartDataset dataset)
+ throws MartServiceException {
+ String qualifiedName = dataset.getQualifiedName();
+ DatasetConfig datasetConfig;
+ if (!datasetConfigMap.containsKey(qualifiedName)) {
+ if (dataset.getModified() != null && cacheDirectory != null) {
+ datasetConfig = getDatasetConfigFromCache(dataset);
+ } else {
+ datasetConfig = MartServiceUtils.getDatasetConfig(location,
+ requestId, dataset);
+ }
+ datasetConfigMap.put(qualifiedName,
+ new SoftReference<DatasetConfig>(datasetConfig));
+ } else {
+ datasetConfig = datasetConfigMap.get(qualifiedName).get();
+ if (datasetConfig == null) {
+ if (dataset.getModified() != null && cacheDirectory != null) {
+ datasetConfig = getDatasetConfigFromCache(dataset);
+ } else {
+ datasetConfig = MartServiceUtils.getDatasetConfig(location,
+ requestId, dataset);
+ }
+ datasetConfigMap.put(qualifiedName,
+ new SoftReference<DatasetConfig>(datasetConfig));
+ }
+
+ }
+ return datasetConfig;
+ }
+
+ private DatasetConfig getDatasetConfigFromCache(MartDataset dataset)
+ throws MartServiceException {
+ DatasetConfig datasetConfig = null;
+ MartURLLocation mart = dataset.getMartURLLocation();
+ String path = mart.getHost() + fs + mart.getName() + fs
+ + mart.getVirtualSchema();
+ File martCacheDir = new File(cacheDirectory, path);
+ martCacheDir.mkdirs();
+ File cache = new File(martCacheDir, dataset.getName() + ".cfg");
+ DatasetConfigXMLUtils datasetConfigXMLUtils = new DatasetConfigXMLUtils(
+ true);
+ if (cache.exists()) {
+ try {
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(new InputSource(
+ new GZIPInputStream(new FileInputStream(cache))));
+
+ // Document doc =
+ // datasetConfigXMLUtils.getDocumentForXMLStream(new
+ // FileInputStream(cache));
+
+ datasetConfig = datasetConfigXMLUtils
+ .getDatasetConfigForDocument(doc);
+ datasetConfigXMLUtils.loadDatasetConfigWithDocument(
+ datasetConfig, doc);
+ if (!datasetConfig.getModified().trim().equals(
+ dataset.getModified().trim())) {
+ logger.info(" " + datasetConfig.getModified().trim()
+ + " != " + dataset.getModified().trim());
+ logger.info(" Database: "
+ + dataset.getMartURLLocation().getDatabase()
+ + ", Dataset: " + dataset.getName());
+ datasetConfig = null;
+ }
+ } catch (IOException e) {
+ logger.debug("error reading cache from " + cache.getPath(), e);
+ datasetConfig = null;
+ } catch (ConfigurationException e) {
+ logger.debug("error parsing from " + cache.getPath(), e);
+ datasetConfig = null;
+ } catch (JDOMException e) {
+ logger.debug("error parsing from " + cache.getPath(), e);
+ datasetConfig = null;
+ }
+ }
+ if (datasetConfig == null) {
+ datasetConfig = MartServiceUtils.getDatasetConfig(location,
+ requestId, dataset);
+ try {
+ GZIPOutputStream zipOutputStream = new GZIPOutputStream(
+ new FileOutputStream(cache));
+ datasetConfigXMLUtils.writeDatasetConfigToOutputStream(
+ datasetConfig, zipOutputStream);
+ zipOutputStream.flush();
+ zipOutputStream.close();
+ } catch (IOException e) {
+ logger.debug("error writing cache to " + cache.getPath(), e);
+ } catch (ConfigurationException e) {
+ logger.debug("error writing cache to " + cache.getPath(), e);
+ }
+ }
+ return datasetConfig;
+ }
+
+ /**
+ * Returns the importables for a dataset.
+ *
+ * @param dataset
+ * @return the importables for a dataset
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Importable[] getImportables(MartDataset dataset)
+ throws MartServiceException {
+ String qualifiedName = dataset.getQualifiedName();
+ if (!importablesMap.containsKey(qualifiedName)) {
+ try {
+ importablesMap.put(qualifiedName, getDatasetConfig(dataset)
+ .getImportables());
+ } catch (MartServiceException e) {
+ return new Importable[0];
+ }
+ }
+ return importablesMap.get(qualifiedName);
+ }
+
+ /**
+ * Returns the exportables for a dataset.
+ *
+ * @param dataset
+ * @return the exportables for a dataset
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Exportable[] getExportables(MartDataset dataset)
+ throws MartServiceException {
+ String qualifiedName = dataset.getQualifiedName();
+ if (!exportablesMap.containsKey(qualifiedName)) {
+ try {
+ exportablesMap.put(qualifiedName, getDatasetConfig(dataset)
+ .getExportables());
+ } catch (MartServiceException e) {
+ return new Exportable[0];
+ }
+ }
+ return exportablesMap.get(qualifiedName);
+ }
+
+ /**
+ * Sends a <code>Query</code> to the MartService and returns the results
+ * of executing the query.
+ *
+ * The results are returned as an array of lists; one list for each
+ * attribute specified in the query.
+ *
+ * @param query
+ * the query to execute
+ * @return the results of executing the query
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Object[] executeQuery(Query query) throws MartServiceException {
+ // logger.info(MartServiceUtils.queryToXML(query));
+ return MartServiceUtils.getResults(location, requestId, query);
+ }
+
+ /**
+ * Sends a <code>Query</code> to the MartService and writes the results to
+ * the <code>ResultReceiver</code> as each line of the result stream is
+ * read.
+ *
+ * @param query
+ * @param resultReceiver
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ * @throws ResultReceiverException
+ * if the ResultReceiver cannot receive the result
+ * @see ResultReceiver
+ */
+ public void executeQuery(Query query, ResultReceiver resultReceiver)
+ throws MartServiceException, ResultReceiverException {
+ MartServiceUtils.putResults(location, requestId, query, resultReceiver);
+ }
+
+ /**
+ * Returns a list of datasets that can be linked to the specified dataset.
+ *
+ * @param martDataset
+ * @return datasets that can be linked to the specified dataset
+ * @throws MartServiceException
+ */
+ public List<DatasetLink> getLinkableDatasets(MartDataset martDataset)
+ throws MartServiceException {
+ if (!linkableDatasetsMap.containsKey(martDataset)) {
+ List<DatasetLink> linkableDatasets = new ArrayList<DatasetLink>();
+
+ Set<String> importableSet = new HashSet<String>();
+ Importable[] importables = getImportables(martDataset);
+ for (int i = 0; i < importables.length; i++) {
+ importableSet.add(importables[i].getLinkName());
+ }
+
+ MartDataset[] datasets = getDatasets(martDataset.getVirtualSchema());
+ for (int j = 0; j < datasets.length; j++) {
+ if (datasets[j].isVisible()
+ && !datasets[j].getName().equals(martDataset.getName())) {
+ DatasetLink datasetLink = new DatasetLink(datasets[j],
+ martDataset);
+ Exportable[] exportables = getExportables(datasets[j]);
+ for (int k = 0; k < exportables.length; k++) {
+ String link = exportables[k].getLinkName();
+ if (importableSet.contains(link)) {
+ datasetLink.addLink(link);
+ }
+ }
+ if (datasetLink.hasLinks()) {
+ linkableDatasets.add(datasetLink);
+ }
+ }
+ }
+ linkableDatasetsMap.put(martDataset, linkableDatasets);
+ }
+
+ return linkableDatasetsMap.get(martDataset);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj != null) {
+ MartService other = (MartService) obj;
+ if (location == null) {
+ result = other.location == null;
+ } else {
+ result = location.equals(other.location);
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return location.hashCode();
+ }
+
+ public boolean linksCalculated() {
+ return linksCalculated;
+ }
+
+ // java implementation of the perl stuff that calculates links.
+ // all this should go for the next version of biomart.
+
+ public void calculateLinks() throws MartServiceException {
+ synchronized (location) {
+ if (!linksCalculated) {
+ datasetToLinkSetMap.clear();
+ datasetsToPathMap.clear();
+
+ MartDataset[] allDatasets = getDatasets();
+ for (int i = 0; i < allDatasets.length; i++) {
+ MartDataset[] datasets = getDatasets(allDatasets[i]
+ .getVirtualSchema());
+ for (int j = 0; j < datasets.length; j++) {
+ if (!allDatasets[i].getName().equals(
+ datasets[j].getName())) {
+ linkDatasets(allDatasets[i], datasets[j]);
+ }
+ }
+ }
+ for (int i = 0; i < allDatasets.length; i++) {
+ datasetsToPathMap.put(allDatasets[i],
+ dijkstra(allDatasets[i]));
+ }
+ linksCalculated = true;
+ }
+ }
+ }
+
+ public List<MartDataset> getPath(MartDataset source, MartDataset target) {
+ List<MartDataset> path = new ArrayList<MartDataset>();
+
+ Map<MartDataset, MartDataset> pathMap = datasetsToPathMap.get(source);
+
+ MartDataset currentDataset = target;
+
+ while (currentDataset != null) {
+ path.add(0, currentDataset);
+ currentDataset = (MartDataset) pathMap.get(currentDataset);
+ }
+
+ if (path.size() < 2 || !path.get(0).equals(source)
+ || !path.get(path.size() - 1).equals(target)) {
+ return null;
+ }
+
+ return path;
+ }
+
+ public DatasetLink getLinkBetween(MartDataset exportingDataset,
+ MartDataset importingDataset) {
+ Set<DatasetLink> links = datasetToLinkSetMap.get(exportingDataset);
+ for (DatasetLink link : links) {
+ MartDataset targetDataset = link.getTargetDataset();
+ if (importingDataset.equals(targetDataset)) {
+ return link;
+ }
+ }
+
+ return null;
+ }
+
+ public List<DatasetLink> getLinksFrom(MartDataset dataset) {
+ List<DatasetLink> linksFrom = new ArrayList<DatasetLink>();
+ Set<DatasetLink> links = datasetToLinkSetMap.get(dataset);
+ if (links != null) {
+ for (DatasetLink link : links) {
+ if (link.getSourceDataset().equals(dataset)) {
+ linksFrom.add(link);
+ }
+ }
+ }
+ return linksFrom;
+ }
+
+ public void linkDatasets(MartDataset source, MartDataset target)
+ throws MartServiceException {
+ DatasetLink datasetLink = new DatasetLink(source, target);
+ Importable[] importables = getImportables(target);
+ for (int i = 0; i < importables.length; i++) {
+ Exportable[] exportables = getExportables(source);
+ for (int j = 0; j < exportables.length; j++) {
+ if (importables[i].getLinkName().equals(
+ exportables[j].getLinkName())) {
+ String importVersion = importables[i].getLinkVersion();
+ String exportVersion = exportables[j].getLinkVersion();
+ if (importVersion != null && exportVersion != null) {
+ if (importVersion.equals(exportVersion)) {
+ datasetLink.addLink(importables[i].getLinkName());
+ }
+ } else {
+ datasetLink.addLink(importables[i].getLinkName());
+ }
+ }
+ }
+ }
+ if (datasetLink.hasLinks()) {
+ if (!datasetToLinkSetMap.containsKey(source)) {
+ datasetToLinkSetMap.put(source, new HashSet<DatasetLink>());
+ }
+ if (!datasetToLinkSetMap.containsKey(target)) {
+ datasetToLinkSetMap.put(target, new HashSet<DatasetLink>());
+ }
+ datasetToLinkSetMap.get(source).add(datasetLink);
+ datasetToLinkSetMap.get(target).add(datasetLink);
+ }
+ }
+
+ public Map<MartDataset, MartDataset> dijkstra(MartDataset dataset)
+ throws MartServiceException {
+ Map<MartDataset, MartDataset> path = new HashMap<MartDataset, MartDataset>();
+ LinkedList<MartDataset> vertices = new LinkedList<MartDataset>(Arrays
+ .asList(getDatasets(dataset.getVirtualSchema())));
+ Map<MartDataset, Integer> dist = new HashMap<MartDataset, Integer>();
+ for (MartDataset vertex : vertices) {
+ dist.put(vertex, new Integer(10000));
+ }
+
+ dist.put(dataset, new Integer(0));
+
+ while (vertices.size() > 0) {
+ int min_vert_idx = 0;
+ MartDataset min_vert = (MartDataset) vertices.get(min_vert_idx);
+ int min_dist = ((Integer) dist.get(min_vert)).intValue();
+
+ for (int vertex_idx = 0; vertex_idx < vertices.size(); vertex_idx++) {
+ MartDataset vertex = (MartDataset) vertices.get(vertex_idx);
+ if (((Integer) dist.get(vertex)).intValue() < min_dist) {
+ min_vert_idx = vertex_idx;
+ min_vert = vertex;
+ min_dist = ((Integer) dist.get(vertex)).intValue();
+ }
+ }
+
+ if (min_dist == 10000) {
+ // Exhausted a disjoint set of datasets.
+ break;
+ }
+
+ vertices.remove(min_vert_idx);
+
+ List<DatasetLink> edges = getLinksFrom(min_vert);
+ for (DatasetLink edge : edges) {
+ MartDataset vertex = edge.getTargetDataset();
+
+ if (((Integer) dist.get(vertex)).intValue() > ((Integer) dist
+ .get(min_vert)).intValue() + 1) {
+ dist.put(vertex, new Integer(((Integer) dist.get(min_vert))
+ .intValue() + 1));
+ path.put(vertex, min_vert);
+ }
+ }
+ }
+
+ return path;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceException.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceException.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceException.java
new file mode 100644
index 0000000..f1f0639
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceException.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceException.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:05 $
+ * by $Author: davidwithers $
+ * Created on 05-May-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+/**
+ * Thrown when a MartService is inaccessable or returns an error.
+ *
+ * @author David Withers
+ */
+public class MartServiceException extends Exception {
+ private static final long serialVersionUID = 5535008907746588537L;
+
+ /**
+ * Constructs a new exception with no detail message.
+ *
+ */
+ public MartServiceException() {
+ super();
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message
+ * the detail message
+ * @param cause
+ * the cause (a null value is permitted, and indicates that the
+ * cause is nonexistent or unknown)
+ */
+ public MartServiceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message
+ * the detail message
+ */
+ public MartServiceException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause.
+ *
+ * @param cause
+ * the cause (a null value is permitted, and indicates that the
+ * cause is nonexistent or unknown)
+ */
+ public MartServiceException(Throwable cause) {
+ super(cause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceUtils.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceUtils.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceUtils.java
new file mode 100644
index 0000000..cdcb400
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceUtils.java
@@ -0,0 +1,725 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceUtils.java,v $
+ * Revision $Revision: 1.12 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/07/31 15:06:49 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.biomart.martservice.query.Attribute;
+import org.biomart.martservice.query.Dataset;
+import org.biomart.martservice.query.Query;
+import org.biomart.martservice.query.QueryXMLHandler;
+import org.ensembl.mart.lib.config.ConfigurationException;
+import org.ensembl.mart.lib.config.DatasetConfig;
+import org.ensembl.mart.lib.config.DatasetConfigXMLUtils;
+import org.jdom.DocType;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
+import org.xml.sax.InputSource;
+
+/**
+ * Utility class for interacting with a BioMart web service.
+ *
+ * @author David Withers
+ */
+public class MartServiceUtils {
+ private static Logger logger = Logger.getLogger(MartServiceUtils.class);
+
+ private static String lineSeparator = System.getProperty("line.separator");
+
+ public static final String QUERY_ATTRIBUTE = "query";
+
+ public static final String DATASET_ATTRIBUTE = "dataset";
+
+ public static final String MART_ATTRIBUTE = "mart";
+
+ public static final String SCHEMA_ATTRIBUTE = "virtualschema";
+
+ public static final String TYPE_ATTRIBUTE = "type";
+
+ public static final String MART_USER_ATTRIBUTE = "martuser";
+
+ public static final String INTERFACE_ATTRIBUTE = "interface";
+
+ public static final String REQUEST_ID_ATTRIBUTE = "requestid";
+
+ public static final String REGISTRY_VALUE = "registry";
+
+ public static final String VERSION_VALUE = "version";
+
+ public static final String DATASETS_VALUE = "datasets";
+
+ public static final String DATASET_VALUE = "dataset";
+
+ public static final String CONFIGURATION_VALUE = "configuration";
+
+ /**
+ * Sends a registry request to the Biomart webservice and constructs a
+ * MartRegistry from the XML returned by the webservice.
+ *
+ * @param martServiceLocation
+ * the URL of the Biomart webservice
+ * @return a MartRegistry
+ * @throws MartServiceException
+ * if the Biomart webservice returns an error or is unavailable
+ */
+ public static MartRegistry getRegistry(String martServiceLocation,
+ String requestId) throws MartServiceException {
+ List<NameValuePair> data = new ArrayList<NameValuePair>();
+ data.add(new NameValuePair(TYPE_ATTRIBUTE, REGISTRY_VALUE));
+ if (requestId != null) {
+ data.add(new NameValuePair(REQUEST_ID_ATTRIBUTE, requestId));
+ }
+ HttpMethod method = new GetMethod(martServiceLocation);
+ method.setQueryString(data
+ .toArray(new NameValuePair[data.size()]));
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+ Document document = new SAXBuilder().build(in);
+ Element root = document.getRootElement();
+ return MartServiceXMLHandler.elementToRegistry(root,
+ Namespace.NO_NAMESPACE);
+ } catch (IOException e) {
+ String errorMessage = "Error getting registry from "
+ + martServiceLocation;
+ throw new MartServiceException(errorMessage, e);
+ } catch (JDOMException e) {
+ String errorMessage = "Error getting registry from "
+ + martServiceLocation;
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+
+ }
+
+ public static String getVersion(String martServiceLocation,
+ String requestId, MartURLLocation mart) throws MartServiceException {
+ String errorMessage = "Error getting version from " + martServiceLocation;
+
+ List<NameValuePair> data = new ArrayList<NameValuePair>();
+ data.add(new NameValuePair(TYPE_ATTRIBUTE, VERSION_VALUE));
+ if (mart.getVirtualSchema() != null) {
+ data.add(new NameValuePair(SCHEMA_ATTRIBUTE, mart
+ .getVirtualSchema()));
+ }
+ data.add(new NameValuePair(MART_ATTRIBUTE, mart.getName()));
+ if (requestId != null) {
+ data.add(new NameValuePair(REQUEST_ID_ATTRIBUTE, requestId));
+ }
+ if (requestId != null) {
+ data.add(new NameValuePair(REQUEST_ID_ATTRIBUTE, requestId));
+ }
+ HttpMethod method = new GetMethod(martServiceLocation);
+ method.setQueryString(data
+ .toArray(new NameValuePair[data.size()]));
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+ BufferedReader bufferedReader = new BufferedReader(
+ new InputStreamReader(in));
+ String version = bufferedReader.readLine();
+ if (version == null) {
+ throw new MartServiceException(errorMessage + ": No version returned");
+ }
+ version = version.trim();
+ // fix for biomart's 'let's add a blank line' thing
+ if ("".equals(version)) {
+ version = bufferedReader.readLine();
+ if (version == null) {
+ throw new MartServiceException(errorMessage + ": No version returned");
+ }
+ version = version.trim();
+ }
+ bufferedReader.close();
+ return version;
+ } catch (IOException e) {
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+ }
+
+ /**
+ * Sends a datasets request to the Biomart webservice and constructs an
+ * array of MartDataset from the tab separated rows of data returned by the
+ * webservice.
+ *
+ * @param martServiceLocation
+ * the URL of the Biomart webservice
+ * @param mart
+ * the mart to get datasets from
+ * @return an array of MartDataset
+ * @throws MartServiceException
+ * if the Biomart webservice returns an error or is unavailable
+ */
+ public static MartDataset[] getDatasets(String martServiceLocation,
+ String requestId, MartURLLocation mart) throws MartServiceException {
+ List<NameValuePair> data = new ArrayList<NameValuePair>();
+ data.add(new NameValuePair(TYPE_ATTRIBUTE, DATASETS_VALUE));
+ if (mart.getVirtualSchema() != null) {
+ data.add(new NameValuePair(SCHEMA_ATTRIBUTE, mart
+ .getVirtualSchema()));
+ }
+ data.add(new NameValuePair(MART_ATTRIBUTE, mart.getName()));
+ if (mart.getMartUser() != null) {
+ data
+ .add(new NameValuePair(MART_USER_ATTRIBUTE, mart
+ .getMartUser()));
+ }
+ if (requestId != null) {
+ data.add(new NameValuePair(REQUEST_ID_ATTRIBUTE, requestId));
+ }
+ HttpMethod method = new GetMethod(martServiceLocation);
+ method.setQueryString(data
+ .toArray(new NameValuePair[data.size()]));
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+
+ MartDataset[] datasets = tabSeparatedReaderToDatasets(
+ new InputStreamReader(in), mart);
+ in.close();
+ return datasets;
+ } catch (IOException e) {
+ String errorMessage = "Error getting datasets from "
+ + martServiceLocation;
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+ }
+
+ /**
+ * Sends a configuration request to the Biomart webservice and constructs a
+ * DatasetConfig from the XML returned by the webservice.
+ *
+ * @param martServiceLocation
+ * the URL of the Biomart webservice
+ * @param dataset
+ * the dataset to get the configuration for
+ * @return a DatasetConfig
+ * @throws MartServiceException
+ * if the Biomart webservice returns an error or is unavailable
+ */
+ public static DatasetConfig getDatasetConfig(String martServiceLocation,
+ String requestId, MartDataset dataset) throws MartServiceException {
+ List<NameValuePair> data = new ArrayList<NameValuePair>();
+ data.add(new NameValuePair(TYPE_ATTRIBUTE, CONFIGURATION_VALUE));
+ MartURLLocation mart = dataset.getMartURLLocation();
+ // if the dataset has a location specify the virtual schema to uniquely
+ // identify the dataset
+ if (mart != null && mart.getVirtualSchema() != null) {
+ data.add(new NameValuePair(SCHEMA_ATTRIBUTE, mart
+ .getVirtualSchema()));
+ }
+ data.add(new NameValuePair(DATASET_VALUE, dataset.getName()));
+// if (dataset.getInterface() != null) {
+// data.add(new NameValuePair(INTERFACE_ATTRIBUTE, dataset
+// .getInterface()));
+// }
+ if (mart != null && mart.getMartUser() != null) {
+ data
+ .add(new NameValuePair(MART_USER_ATTRIBUTE, mart
+ .getMartUser()));
+ }
+ if (requestId != null) {
+ data.add(new NameValuePair(REQUEST_ID_ATTRIBUTE, requestId));
+ }
+ HttpMethod method = new GetMethod(martServiceLocation);
+ method.setQueryString(data
+ .toArray(new NameValuePair[data.size()]));
+
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+
+ DatasetConfigXMLUtils datasetConfigXMLUtils = new DatasetConfigXMLUtils(
+ true);
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(new InputSource(in));
+ // Document doc = datasetConfigXMLUtils.getDocumentForXMLStream(in);
+
+ DatasetConfig datasetConfig = datasetConfigXMLUtils
+ .getDatasetConfigForDocument(doc);
+ datasetConfigXMLUtils.loadDatasetConfigWithDocument(datasetConfig,
+ doc);
+ return datasetConfig;
+ } catch (ConfigurationException e) {
+ String errorMessage = "Error parsing configuration from "
+ + martServiceLocation;
+ logger.debug(errorMessage, e);
+ throw new MartServiceException(errorMessage, e);
+ } catch (JDOMException e) {
+ String errorMessage = "Error parsing configuration from "
+ + martServiceLocation;
+ logger.debug(errorMessage, e);
+ throw new MartServiceException(errorMessage, e);
+ } catch (IOException e) {
+ String errorMessage = "Error getting configuration from "
+ + martServiceLocation;
+ logger.debug(errorMessage, e);
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+ }
+
+ /**
+ * Sends a query to the Biomart webservice and constructs an array of List
+ * of String results from the tab separated rows of data returned by the
+ * webservice.
+ *
+ * @param martServiceLocation
+ * the URL of the Biomart webservice
+ * @param query
+ * the query to send to the webservice
+ * @return an array of List of String
+ * @throws MartServiceException
+ * if the Biomart webservice returns an error or is unavailable
+ */
+ public static Object[] getResults(String martServiceLocation,
+ String requestId, Query query) throws MartServiceException {
+ Object[] results = new Object[0];
+ // int attributes = query.getAttributes().size();
+ int attributes = getAttributeCount(query.getAttributes());
+ boolean count = query.getCount() == 1;
+ // if there are no attributes and we're not doing a count there's no
+ // point in doing the query
+ if (attributes > 0 || count) {
+ // The 'new' 0.5 server now resolves the attribute lists so there's
+ // no need to do the split here any more
+ // String queryXml = queryToXML(splitAttributeLists(query));
+ String queryXml = queryToXML(query);
+ logger.info(queryXml);
+ NameValuePair[] data = { new NameValuePair(QUERY_ATTRIBUTE,
+ queryXml) };
+ PostMethod method = new PostMethod(martServiceLocation);
+ method.setRequestBody(data);
+
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+ if (query.getFormatter() == null) {
+ results = tabSeparatedReaderToResults(
+ new InputStreamReader(in), count ? 1 : attributes);
+ if (!count) {
+ results = reassembleAttributeLists(results, query);
+ }
+ } else {
+ results = readResult(in, query.getFormatter());
+ }
+ in.close();
+ } catch (IOException e) {
+ String errorMessage = "Error reading data from "
+ + martServiceLocation;
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+
+ }
+
+ return results;
+ }
+
+ public static void putResults(String martServiceLocation, String requestId,
+ Query query, ResultReceiver resultReceiver) throws MartServiceException, ResultReceiverException {
+ int attributeCount = getAttributeCount(query.getAttributes());
+ boolean count = query.getCount() == 1;
+ // if there are no attributes and we're not doing a count there's no
+ // point in doing the query
+ if (attributeCount > 0 || count) {
+ String queryXml = queryToXML(query);
+ logger.info(queryXml);
+ NameValuePair[] data = { new NameValuePair(QUERY_ATTRIBUTE,
+ queryXml) };
+ PostMethod method = new PostMethod(martServiceLocation);
+ method.setRequestBody(data);
+
+ try {
+ InputStream in = executeMethod(method, martServiceLocation);
+ if (query.getFormatter() == null) {
+ if (count) {
+ resultReceiver.receiveResult(tabSeparatedReaderToResults(new InputStreamReader(in), 1), 0);
+ } else {
+ List<Attribute> attributes = query.getAttributes();
+ Object[] result = new Object[attributes.size()];
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
+ String line = bufferedReader.readLine();
+ for (long i = 0; line != null; line = bufferedReader.readLine(), i++) {
+ String[] tokens = line.split("\t", -1);
+ if (attributeCount == tokens.length) {
+ for (int ri = 0, ti = 0; ri < result.length && ti < tokens.length; ri++) {
+ Attribute attribute = attributes.get(ri);
+ if (attribute.getAttributes() == null) {
+ result[ri] = tokens[ti];
+ ti++;
+ } else {
+ int nestedAttributeCount = attribute.getAttributesCount();
+ List<Object> list = new ArrayList<Object>();
+ for (int j = 0; j < nestedAttributeCount; j++) {
+ list.add(tokens[ti]);
+ ti++;
+ }
+ result[ri] = list;
+ }
+ }
+ resultReceiver.receiveResult(result, i);
+ } else {
+ resultReceiver.receiveError(line, i);
+ }
+ }
+ }
+ } else {
+ resultReceiver.receiveResult(readResult(in, query.getFormatter()), 0);
+ }
+ in.close();
+ } catch (IOException e) {
+ String errorMessage = "Error reading data from "
+ + martServiceLocation;
+ throw new MartServiceException(errorMessage, e);
+ } finally {
+ method.releaseConnection();
+ }
+
+ }
+ }
+
+// private static String getLocation(MartURLLocation martUrlLocation) {
+// StringBuffer location = new StringBuffer("http://");
+// location.append(martUrlLocation.getHost());
+// location.append(":" + martUrlLocation.getPort());
+// location.append(martUrlLocation.getPath());
+// return location.toString();
+// }
+
+ private static int getAttributeCount(List<Attribute> attributeList) {
+ int result = 0;
+ for (Attribute attribute : attributeList) {
+ if (attribute.getAttributes() == null) {
+ result++;
+ } else {
+ result += attribute.getAttributesCount();
+ }
+ }
+ return result;
+ }
+
+ private static Object[] reassembleAttributeLists(Object[] lists, Query query) {
+ int index = 0;
+ List<Object> result = new ArrayList<Object>();
+ for (Attribute attribute : query.getAttributes()) {
+ if (attribute.getAttributes() == null) {
+ result.add(lists[index]);
+ index++;
+ } else {
+ int attributesCount = attribute.getAttributesCount();
+ List<Object> list = new ArrayList<Object>();
+ for (int i = 0; i < attributesCount; i++) {
+ list.add(lists[index]);
+ index++;
+ }
+ result.add(list);
+ }
+ }
+ return result.toArray();
+ }
+
+ public static Query splitAttributeLists(Query query) {
+ Query result = new Query(query);
+ for (Dataset dataset : result.getDatasets()) {
+ List<Attribute> attributeList = dataset.getAttributes();
+ dataset.removeAllAttributes();
+ for (Attribute attribute : attributeList) {
+ if (attribute.getAttributes() == null) {
+ dataset.addAttribute(attribute);
+ } else {
+ String[] attributes = attribute.getAttributes().split(",");
+ for (int i = 0; i < attributes.length; i++) {
+ dataset.addAttribute(new Attribute(attributes[i]));
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public static String getMimeTypeForFormatter(String formatter) {
+ String mimeType = "'text/plain'";
+ if ("ADF".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("AXT".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("AXTPLUS".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("CSV".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("FASTA".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("FASTACDNA".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("GFF".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("HTML".equals(formatter)) {
+ mimeType = "'text/html'";
+ } else if ("MAF".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("MFA".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("MFASTA".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("TSV".equals(formatter)) {
+ mimeType = "'text/tab-separeted-values'";
+ } else if ("TXT".equals(formatter)) {
+ mimeType = "'text/plain'";
+ } else if ("XLS".equals(formatter)) {
+ mimeType = "'application/excel'";
+ }
+
+ return mimeType;
+ }
+
+ private static List<String>[] tabSeparatedReaderToResults(Reader reader,
+ int resultsCount) throws IOException {
+ List<String>[] results = new List[resultsCount];
+ for (int i = 0; i < results.length; i++) {
+ results[i] = new ArrayList<String>();
+ }
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ String line = bufferedReader.readLine();
+ while (line != null) {
+ String[] tokens = line.split("\t", -1);
+ for (int i = 0; i < results.length && i < tokens.length; i++) {
+ results[i].add(tokens[i]);
+ }
+ line = bufferedReader.readLine();
+ }
+ return results;
+ }
+
+ private static Object[] readResult(InputStream inputStream, String formatter) throws IOException {
+ Object[] result = new Object[1];
+
+ if (getMimeTypeForFormatter(formatter).contains("application/")) {
+ result[0] = IOUtils.toByteArray(inputStream);
+ } else {
+ result[0] = IOUtils.toString(inputStream);
+ }
+ return result;
+ }
+
+ private static MartDataset[] tabSeparatedReaderToDatasets(Reader reader,
+ MartURLLocation martURLLocation) throws IOException {
+ List<MartDataset> datasetList = new ArrayList<MartDataset>();
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ String line = bufferedReader.readLine();
+ while (line != null) {
+ String[] tokens = line.split("\t");
+
+ if (tokens.length >= 7) {
+ MartDataset dataset = new MartDataset();
+
+ dataset.setType(tokens[0]);
+ dataset.setName(tokens[1]);
+ dataset.setDisplayName(tokens[2]);
+ if (tokens[3].equals("1")) {
+ dataset.setVisible(true);
+ } else {
+ dataset.setVisible(false);
+ }
+ // value at position 4 is not documented so it's skipped
+ try {
+ dataset.setInitialBatchSize(Long.parseLong(tokens[5]));
+ } catch (NumberFormatException e) {
+ dataset.setInitialBatchSize(0);
+ }
+ try {
+ dataset.setMaximumBatchSize(Long.parseLong(tokens[6]));
+ } catch (NumberFormatException e) {
+ dataset.setMaximumBatchSize(0);
+ }
+
+ if (tokens.length > 7) {
+ dataset.setInterface(tokens[7]);
+ dataset.setModified(tokens[8]);
+ }
+
+ dataset.setMartURLLocation(martURLLocation);
+
+ datasetList.add(dataset);
+ }
+ line = bufferedReader.readLine();
+ }
+ return datasetList.toArray(new MartDataset[datasetList.size()]);
+ }
+
+ /**
+ * Creates an XML string from a query
+ *
+ * @param query
+ * @return an XML string
+ */
+ public static String queryToXML(Query query) {
+ Document document = new Document(QueryXMLHandler.queryToElement(query,
+ Namespace.NO_NAMESPACE), new DocType("Query"));
+ return new XMLOutputter().outputString(document);
+ }
+
+ /**
+ * @param martServiceLocation
+ * @param data
+ * @return
+ * @throws MartServiceException
+ */
+ private static InputStream executeMethod(HttpMethod method,
+ String martServiceLocation) throws MartServiceException {
+ HttpClient client = new HttpClient();
+ if (isProxyHost(martServiceLocation)) {
+ setProxy(client);
+ }
+
+ method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
+ new DefaultHttpMethodRetryHandler(3, false));
+// method.getParams().setSoTimeout(60000);
+ try {
+ int statusCode = client.executeMethod(method);
+ if (statusCode != HttpStatus.SC_OK) {
+ throw constructException(method, martServiceLocation, null);
+ }
+ return method.getResponseBodyAsStream();
+ } catch (IOException e) {
+ throw constructException(method, martServiceLocation, e);
+ }
+ }
+
+ /**
+ *
+ * @param client
+ */
+ public static void setProxy(HttpClient client) {
+ String host = System.getProperty("http.proxyHost");
+ String port = System.getProperty("http.proxyPort");
+ String user = System.getProperty("http.proxyUser");
+ String password = System.getProperty("http.proxyPassword");
+
+ if (host != null && port != null) {
+ try {
+ int portInteger = Integer.parseInt(port);
+ client.getHostConfiguration().setProxy(host, portInteger);
+ if (user != null && password != null) {
+ client.getState().setProxyCredentials(
+ new AuthScope(host, portInteger),
+ new UsernamePasswordCredentials(user, password));
+ }
+ } catch (NumberFormatException e) {
+ logger.error("Proxy port not an integer", e);
+ }
+ }
+ }
+
+ public static boolean isProxyHost(String location) {
+ String httpNonProxyHosts = System.getProperty("http.nonProxyHosts");
+ if (httpNonProxyHosts != null) {
+ try {
+ String host = new URL(location).getHost();
+ String[] nonProxyHosts = httpNonProxyHosts.split("\\|");
+ for (int i = 0; i < nonProxyHosts.length; i++) {
+ if (nonProxyHosts[i].startsWith("*")) {
+ if (host.endsWith(nonProxyHosts[i].substring(1))) {
+ return false;
+ }
+ } else if (nonProxyHosts[i].endsWith("*")) {
+ if (host.startsWith(nonProxyHosts[i].substring(0,
+ nonProxyHosts[i].length() - 1))) {
+ return false;
+ }
+ } else {
+ if (host.equals(nonProxyHosts[i])) {
+ return false;
+ }
+ }
+ }
+ } catch (MalformedURLException e) {
+ logger.warn("'" + location + "' is not a valid URL. "
+ + "Cannot compare host with http.nonProxyHosts", e);
+ }
+ }
+ return true;
+ }
+
+ private static MartServiceException constructException(HttpMethod method,
+ String martServiceLocation, Exception cause) {
+ StringBuffer errorMessage = new StringBuffer();
+ errorMessage.append("Error posting to " + martServiceLocation
+ + lineSeparator);
+ if (cause == null) {
+ errorMessage.append(" " + method.getStatusLine()
+ + lineSeparator);
+ }
+ if (method instanceof PostMethod) {
+ PostMethod postMethod = (PostMethod) method;
+ NameValuePair[] data = postMethod.getParameters();
+ for (int i = 0; i < data.length; i++) {
+ errorMessage.append(" " + data[i].getName() + " = "
+ + data[i].getValue()
+ + lineSeparator);
+ }
+
+ } else {
+ errorMessage.append(method.getQueryString());
+ }
+ return new MartServiceException(errorMessage.toString(), cause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceXMLHandler.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceXMLHandler.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceXMLHandler.java
new file mode 100644
index 0000000..e8a5189
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartServiceXMLHandler.java
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartServiceXMLHandler.java,v $
+ * Revision $Revision: 1.4 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:55 $
+ * by $Author: davidwithers $
+ * Created on 28-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.biomart.martservice.query.QueryXMLHandler;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * Utility class for serializing mart service classes to XML.
+ *
+ * @author David Withers
+ */
+public class MartServiceXMLHandler {
+ public static final String MART_SERVICE_ELEMENT = "MartService";
+
+ public static final String MART_URL_LOCATION_ELEMENT = "MartURLLocation";
+
+ public static final String MART_DATASET_ELEMENT = "MartDataset";
+
+ public static final String MART_QUERY_ELEMENT = "MartQuery";
+
+ public static final String LINKED_DATASETS_ELEMENT = "LinkedDatasets";
+
+ public static final String LINKED_DATASET_ELEMENT = "LinkedDataset";
+
+ public static final String VIRTUAL_SCHEMA_ELEMENT = "virtualSchema";
+
+ public static final String LOCATION_ATTRIBUTE = "location";
+
+ public static final String DATABASE_ATTRIBUTE = "database";
+
+ public static final String DEFAULT_ATTRIBUTE = "default";
+
+ public static final String DEFAULT_VALUE_ATTRIBUTE = "defaultValue";
+
+ public static final String DISPLAY_NAME_ATTRIBUTE = "displayName";
+
+ public static final String HOST_ATTRIBUTE = "host";
+
+ public static final String INCLUDE_DATASETS_ATTRIBUTE = "includeDatasets";
+
+ public static final String LINK_ATTRIBUTE = "LINK";
+
+ public static final String MART_USER_ATTRIBUTE = "martUser";
+
+ public static final String NAME_ATTRIBUTE = "name";
+
+ public static final String PATH_ATTRIBUTE = "path";
+
+ public static final String PORT_ATTRIBUTE = "port";
+
+ public static final String TYPE_ATTRIBUTE = "type";
+
+ public static final String INITIAL_BATCH_SIZE_ATTRIBUTE = "initialBatchSize";
+
+ public static final String MAXIMUM_BATCH_SIZE_ATTRIBUTE = "maximumBatchSize";
+
+ public static final String VIRTUAL_SCHEMA_ATTRIBUTE = "virtualSchema";
+
+ public static final String SERVER_VIRTUAL_SCHEMA_ATTRIBUTE = "serverVirtualSchema";
+
+ public static final String VISIBLE_ATTRIBUTE = "visible";
+
+ public static final String REDIRECT_ATTRIBUTE = "redirect";
+
+ public static final String INTERFACE_ATTRIBUTE = "interface";
+
+ public static final String MODIFIED_ATTRIBUTE = "modified";
+
+ /**
+ * Converts a <code>MartService</code> to an XML element.
+ *
+ * @param martService
+ * the <code>MartService</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>MartService</code>
+ */
+ public static Element martServiceToElement(MartService martService,
+ Namespace namespace) {
+ Element element = new Element(MART_SERVICE_ELEMENT, namespace);
+ element.setAttribute(LOCATION_ATTRIBUTE, martService.getLocation());
+ return element;
+ }
+
+ /**
+ * Creates a <code>MartService</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @return a deserialized <code>MartService</code>
+ */
+ public static MartService elementToMartService(Element element) {
+ return MartService.getMartService(element
+ .getAttributeValue(LOCATION_ATTRIBUTE));
+ }
+
+ /**
+ * Converts a <code>MartDataset</code> to an XML element.
+ *
+ * @param dataset
+ * the <code>MartDataset</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>MartDataset</code>
+ */
+ public static Element datasetToElement(MartDataset dataset,
+ Namespace namespace) {
+ Element element = new Element(MART_DATASET_ELEMENT, namespace);
+ element.setAttribute(DISPLAY_NAME_ATTRIBUTE, dataset.getDisplayName());
+ element.setAttribute(NAME_ATTRIBUTE, dataset.getName());
+ element.setAttribute(TYPE_ATTRIBUTE, dataset.getType());
+ element.setAttribute(INITIAL_BATCH_SIZE_ATTRIBUTE, String
+ .valueOf(dataset.getInitialBatchSize()));
+ element.setAttribute(MAXIMUM_BATCH_SIZE_ATTRIBUTE, String
+ .valueOf(dataset.getMaximumBatchSize()));
+ element.setAttribute(VISIBLE_ATTRIBUTE, String.valueOf(dataset
+ .isVisible()));
+ if (dataset.getInterface() != null) {
+ element.setAttribute(INTERFACE_ATTRIBUTE, dataset.getInterface());
+ }
+ if (dataset.getModified() != null) {
+ element.setAttribute(MODIFIED_ATTRIBUTE, dataset.getModified());
+ }
+ element.addContent(locationToElement(dataset.getMartURLLocation(),
+ namespace));
+ return element;
+ }
+
+ /**
+ * Creates a <code>MartDataset</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @param namespace
+ * the <code>Namespace</code> containing the
+ * <code>Element</code>
+ * @return a deserialized <code>MartDataset</code>
+ */
+ public static MartDataset elementToDataset(Element element,
+ Namespace namespace) {
+ MartDataset dataset = new MartDataset();
+ dataset.setDisplayName(element
+ .getAttributeValue(DISPLAY_NAME_ATTRIBUTE));
+ dataset.setName(element.getAttributeValue(NAME_ATTRIBUTE));
+ dataset.setType(element.getAttributeValue(TYPE_ATTRIBUTE));
+ dataset.setInitialBatchSize(Long.parseLong(element
+ .getAttributeValue(INITIAL_BATCH_SIZE_ATTRIBUTE)));
+ dataset.setMaximumBatchSize(Long.parseLong(element
+ .getAttributeValue(MAXIMUM_BATCH_SIZE_ATTRIBUTE)));
+ dataset.setVisible(Boolean.getBoolean(element
+ .getAttributeValue(VISIBLE_ATTRIBUTE)));
+ dataset.setInterface(element.getAttributeValue(INTERFACE_ATTRIBUTE));
+ dataset.setModified(element.getAttributeValue(MODIFIED_ATTRIBUTE));
+ dataset.setMartURLLocation(elementToLocation(element.getChild(
+ MART_URL_LOCATION_ELEMENT, namespace)));
+ return dataset;
+ }
+
+ /**
+ * Creates a <code>MartRegistry</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @param namespace
+ * the <code>Namespace</code> containing the
+ * <code>Element</code>
+ * @return a deserialized <code>MartRegistry</code>
+ */
+ public static MartRegistry elementToRegistry(Element root,
+ Namespace namespace) {
+ MartRegistry registry = new MartRegistry();
+ List<Element> children = root.getChildren();
+ for (Element childElement : children) {
+ if (childElement.getNamespace().equals(namespace)) {
+ if (childElement.getName().equals(MART_URL_LOCATION_ELEMENT)) {
+ MartURLLocation martURLLocation = MartServiceXMLHandler
+ .elementToLocation(childElement);
+ martURLLocation.setVirtualSchema("default");
+ registry.addMartURLLocation(martURLLocation);
+ } else if (childElement.getName()
+ .equals(VIRTUAL_SCHEMA_ELEMENT)) {
+ String virtualSchema = childElement
+ .getAttributeValue(NAME_ATTRIBUTE);
+ List<Element> locations = childElement.getChildren(
+ MART_URL_LOCATION_ELEMENT, namespace);
+ for (Element location : locations) {
+ MartURLLocation martURLLocation = MartServiceXMLHandler
+ .elementToLocation(location);
+ martURLLocation.setVirtualSchema(virtualSchema);
+ registry.addMartURLLocation(martURLLocation);
+ }
+ }
+ }
+ }
+ return registry;
+ }
+
+ /**
+ * Converts a <code>MartURLLocation</code> to an XML element.
+ *
+ * @param location
+ * the <code>MartURLLocation</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>MartURLLocation</code>
+ */
+ public static Element locationToElement(MartURLLocation location,
+ Namespace namespace) {
+ Element element = new Element(MART_URL_LOCATION_ELEMENT, namespace);
+ if (location.getDatabase() != null) {
+ element.setAttribute(DATABASE_ATTRIBUTE, location.getDatabase());
+ }
+ element.setAttribute(DEFAULT_ATTRIBUTE, location.isDefault() ? "1"
+ : "0");
+ element.setAttribute(DISPLAY_NAME_ATTRIBUTE, location.getDisplayName());
+ element.setAttribute(HOST_ATTRIBUTE, location.getHost());
+ if (location.getIncludeDatasets() != null) {
+ element.setAttribute(INCLUDE_DATASETS_ATTRIBUTE, location
+ .getIncludeDatasets());
+ }
+ if (location.getMartUser() != null) {
+ element.setAttribute(MART_USER_ATTRIBUTE, location.getMartUser());
+ }
+ element.setAttribute(NAME_ATTRIBUTE, location.getName());
+ if (location.getPath() != null) {
+ element.setAttribute(PATH_ATTRIBUTE, location.getPath());
+ }
+ element
+ .setAttribute(PORT_ATTRIBUTE, String
+ .valueOf(location.getPort()));
+ element.setAttribute(SERVER_VIRTUAL_SCHEMA_ATTRIBUTE, location
+ .getServerVirtualSchema());
+ if (location.getVirtualSchema() != null) {
+ element.setAttribute(VIRTUAL_SCHEMA_ATTRIBUTE, location
+ .getVirtualSchema());
+ }
+ element.setAttribute(VISIBLE_ATTRIBUTE, location.isVisible() ? "1"
+ : "0");
+ element.setAttribute(REDIRECT_ATTRIBUTE, location.isRedirect() ? "1"
+ : "0");
+ return element;
+ }
+
+ /**
+ * Creates a <code>MartURLLocation</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @return a deserialized <code>MartURLLocation</code>
+ */
+ public static MartURLLocation elementToLocation(Element element) {
+ MartURLLocation location = new MartURLLocation();
+ location.setDatabase(element.getAttributeValue(DATABASE_ATTRIBUTE));
+ location.setDefault("1".equals(element
+ .getAttributeValue(DEFAULT_ATTRIBUTE)));
+ location.setDisplayName(element
+ .getAttributeValue(DISPLAY_NAME_ATTRIBUTE));
+ location.setHost(element.getAttributeValue(HOST_ATTRIBUTE));
+ location.setIncludeDatasets(element
+ .getAttributeValue(INCLUDE_DATASETS_ATTRIBUTE));
+ location.setMartUser(element.getAttributeValue(MART_USER_ATTRIBUTE));
+ location.setName(element.getAttributeValue(NAME_ATTRIBUTE));
+ location.setPath(element.getAttributeValue(PATH_ATTRIBUTE));
+ try {
+ location.setPort(Integer.parseInt(element
+ .getAttributeValue(PORT_ATTRIBUTE)));
+ } catch (NumberFormatException e) {
+ location.setPort(80);
+ }
+ location.setServerVirtualSchema(element
+ .getAttributeValue(SERVER_VIRTUAL_SCHEMA_ATTRIBUTE));
+ location.setVirtualSchema(element
+ .getAttributeValue(VIRTUAL_SCHEMA_ATTRIBUTE));
+ location.setVisible("1".equals(element
+ .getAttributeValue(VISIBLE_ATTRIBUTE)));
+ location.setRedirect("1".equals(element
+ .getAttributeValue(REDIRECT_ATTRIBUTE)));
+ return location;
+ }
+
+ /**
+ * Creates a <code>MartQuery</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @param namespace
+ * the <code>Namespace</code> containing the
+ * <code>Element</code>
+ * @return a deserialized <code>MartQuery</code>
+ */
+ public static MartQuery elementToMartQuery(Element element,
+ Namespace namespace) {
+ MartQuery martQuery = new MartQuery();
+ martQuery.setMartService(MartServiceXMLHandler
+ .elementToMartService(element.getChild(MART_SERVICE_ELEMENT,
+ namespace)));
+ martQuery.setMartDataset(elementToDataset(element.getChild(
+ MART_DATASET_ELEMENT, namespace), namespace));
+ martQuery.setQuery(QueryXMLHandler.elementToQuery(element.getChild(
+ QueryXMLHandler.QUERY_ELEMENT, namespace), namespace));
+ Element linksElement = element.getChild(LINKED_DATASETS_ELEMENT, namespace);
+ if (linksElement != null) {
+ List linkedDatasets = linksElement.getChildren(LINKED_DATASETS_ELEMENT,
+ namespace);
+ for (Iterator iter = linkedDatasets.iterator(); iter.hasNext();) {
+ Element datasetElement = (Element) iter.next();
+ String datasetName = datasetElement.getAttributeValue(NAME_ATTRIBUTE);
+ String linkId = datasetElement.getAttributeValue(LINK_ATTRIBUTE);
+ martQuery.addLinkedDataset(datasetName, linkId);
+ }
+ }
+ return martQuery;
+ }
+
+ /**
+ * Converts a <code>MartQuery</code> to an XML element.
+ *
+ * @param martQuery
+ * the <code>MartQuery</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>MartQuery</code>
+ */
+ public static Element martQueryToElement(MartQuery martQuery,
+ Namespace namespace) {
+ Element element = new Element(MART_QUERY_ELEMENT, namespace);
+ element.addContent(martServiceToElement(martQuery.getMartService(),
+ namespace));
+ element.addContent(datasetToElement(martQuery.getMartDataset(),
+ namespace));
+ element.addContent(QueryXMLHandler.queryToElement(martQuery.getQuery(),
+ namespace));
+ Set linkedDatasets = martQuery.getLinkedDatasets();
+ if (linkedDatasets.size() > 0) {
+ Element linksElement = new Element(LINKED_DATASETS_ELEMENT, namespace);
+ for (Iterator iter = linkedDatasets.iterator(); iter.hasNext();) {
+ String datasetName = (String) iter.next();
+ Element datasetElement = new Element(LINKED_DATASETS_ELEMENT, namespace);
+ datasetElement.setAttribute(NAME_ATTRIBUTE, datasetName);
+ datasetElement.setAttribute(LINK_ATTRIBUTE, martQuery
+ .getLink(datasetName));
+ linksElement.addContent(datasetElement);
+ }
+ element.addContent(linksElement);
+ }
+ return element;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartURLLocation.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartURLLocation.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartURLLocation.java
new file mode 100644
index 0000000..476956d
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/MartURLLocation.java
@@ -0,0 +1,422 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MartURLLocation.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/04 14:15:59 $
+ * by $Author: davidwithers $
+ * Created on 17-Mar-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+import org.ensembl.mart.lib.config.MartLocation;
+
+/**
+ * The MartURLLocation contained by the MartRegistry returned by a BioMart web
+ * service.
+ *
+ * @author David Withers
+ */
+public class MartURLLocation implements MartLocation {
+ private static final String URL_TYPE = "URL";
+
+ private String database;
+
+ private boolean defaultValue;
+
+ private String displayName;
+
+ private String host;
+
+ private String includeDatasets;
+
+ private String martUser;
+
+ private String name;
+
+ private String path;
+
+ private int port;
+
+ private String serverVirtualSchema;
+
+ private String virtualSchema;
+
+ private boolean visible;
+
+ private boolean redirect;
+
+ /**
+ * Returns the database.
+ *
+ * @return the database
+ */
+ public String getDatabase() {
+ return database;
+ }
+
+ /**
+ * Sets the database.
+ *
+ * @param database the new database
+ */
+ public void setDatabase(String database) {
+ this.database = database;
+ }
+
+ /**
+ * Returns true if the default flag is set.
+ *
+ * @return true if the default flag is set
+ */
+ public boolean isDefault() {
+ return defaultValue;
+ }
+
+ /**
+ * Sets the default flag.
+ *
+ * @param defaultValue
+ * the value of the default flag
+ */
+ public void setDefault(boolean defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Returns the displayName.
+ *
+ * @return the displayName.
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /**
+ * Sets the displayName.
+ *
+ * @param displayName
+ * the displayName to set.
+ */
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ /**
+ * Returns the host.
+ *
+ * @return the host.
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Sets the host.
+ *
+ * @param host
+ * the host to set.
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ /**
+ * Returns the includeDatasets.
+ *
+ * @return the includeDatasets
+ */
+ public String getIncludeDatasets() {
+ return includeDatasets;
+ }
+
+ /**
+ * Sets the includeDatasets.
+ *
+ * @param includeDatasets the new includeDatasets
+ */
+ public void setIncludeDatasets(String includeDatasets) {
+ this.includeDatasets = includeDatasets;
+ }
+
+ /**
+ * Returns the martUser.
+ *
+ * @return the martUser
+ */
+ public String getMartUser() {
+ return martUser;
+ }
+
+ /**
+ * Sets the martUser.
+ *
+ * @param martUser the new martUser
+ */
+ public void setMartUser(String martUser) {
+ this.martUser = martUser;
+ }
+
+ /**
+ * Returns the name
+ *
+ * @return the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name
+ * the name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Sets the path.
+ *
+ * @param path the new path
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Returns the port.
+ *
+ * @return the port.
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * Sets the port.
+ *
+ * @param port
+ * the port to set.
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ /**
+ * Returns the serverVirtualSchema.
+ *
+ * @return the serverVirtualSchema.
+ */
+ public String getServerVirtualSchema() {
+ return serverVirtualSchema;
+ }
+
+ /**
+ * Sets the serverVirtualSchema.
+ *
+ * @param serverVirtualSchema
+ * the serverVirtualSchema to set.
+ */
+ public void setServerVirtualSchema(String serverVirtualSchema) {
+ this.serverVirtualSchema = serverVirtualSchema;
+ }
+
+ /**
+ * Returns the virtualSchema.
+ *
+ * @return the virtualSchema.
+ */
+ public String getVirtualSchema() {
+ return virtualSchema;
+ }
+
+ /**
+ * Sets the virtualSchema.
+ *
+ * @param virtualSchema
+ * the virtualSchema to set.
+ */
+ public void setVirtualSchema(String virtualSchema) {
+ this.virtualSchema = virtualSchema;
+ }
+
+ /**
+ * Returns true if the location is visible.
+ *
+ * @return Returns the visible.
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /**
+ * @param visible
+ * The visible to set.
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
+
+ /**
+ * Returns true if this location is redirected.
+ *
+ * @return the redirect
+ */
+ public boolean isRedirect() {
+ return redirect;
+ }
+
+ /**
+ * @param redirect the redirect to set
+ */
+ public void setRedirect(boolean redirect) {
+ this.redirect = redirect;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ensembl.mart.lib.config.MartLocation#getType()
+ */
+ public String getType() {
+ return URL_TYPE;
+ }
+
+ /**
+ * Returns the display name.
+ *
+ * @return the display name
+ */
+ public String toString() {
+ return getDisplayName();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((database == null) ? 0 : database.hashCode());
+ result = prime * result + (defaultValue ? 1231 : 1237);
+ result = prime * result
+ + ((displayName == null) ? 0 : displayName.hashCode());
+ result = prime * result + ((host == null) ? 0 : host.hashCode());
+ result = prime * result
+ + ((includeDatasets == null) ? 0 : includeDatasets.hashCode());
+ result = prime * result
+ + ((martUser == null) ? 0 : martUser.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ result = prime * result + port;
+ result = prime * result + (redirect ? 1231 : 1237);
+ result = prime
+ * result
+ + ((serverVirtualSchema == null) ? 0 : serverVirtualSchema
+ .hashCode());
+ result = prime * result
+ + ((virtualSchema == null) ? 0 : virtualSchema.hashCode());
+ result = prime * result + (visible ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final MartURLLocation other = (MartURLLocation) obj;
+ if (database == null) {
+ if (other.database != null)
+ return false;
+ } else if (!database.equals(other.database))
+ return false;
+ if (defaultValue != other.defaultValue)
+ return false;
+ if (displayName == null) {
+ if (other.displayName != null)
+ return false;
+ } else if (!displayName.equals(other.displayName))
+ return false;
+ if (host == null) {
+ if (other.host != null)
+ return false;
+ } else if (!host.equals(other.host))
+ return false;
+ if (includeDatasets == null) {
+ if (other.includeDatasets != null)
+ return false;
+ } else if (!includeDatasets.equals(other.includeDatasets))
+ return false;
+ if (martUser == null) {
+ if (other.martUser != null)
+ return false;
+ } else if (!martUser.equals(other.martUser))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (path == null) {
+ if (other.path != null)
+ return false;
+ } else if (!path.equals(other.path))
+ return false;
+ if (port != other.port)
+ return false;
+ if (redirect != other.redirect)
+ return false;
+ if (serverVirtualSchema == null) {
+ if (other.serverVirtualSchema != null)
+ return false;
+ } else if (!serverVirtualSchema.equals(other.serverVirtualSchema))
+ return false;
+ if (virtualSchema == null) {
+ if (other.virtualSchema != null)
+ return false;
+ } else if (!virtualSchema.equals(other.virtualSchema))
+ return false;
+ if (visible != other.visible)
+ return false;
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiver.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiver.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiver.java
new file mode 100644
index 0000000..cc1d062
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiver.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: ResultReceiver.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/07/31 15:06:49 $
+ * by $Author: davidwithers $
+ * Created on Jan 18, 2008
+ *****************************************************************/
+package org.biomart.martservice;
+
+/**
+ * An interface for receiving results of a Query.
+ *
+ * @author David Withers
+ */
+public interface ResultReceiver {
+
+ /**
+ * Receives a single row from the results of executing a Query.
+ *
+ * This method will be called frequently and should not block.
+ *
+ * @param resultRow
+ */
+ public void receiveResult(Object[] resultRow, long index) throws ResultReceiverException;
+
+ /**
+ * Receives an error for a single row from the results of executing a Query.
+ *
+ * This method will be called frequently and should not block.
+ *
+ * @param resultRow
+ */
+ public void receiveError(String errorMessage, long index) throws ResultReceiverException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiverException.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiverException.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiverException.java
new file mode 100644
index 0000000..c3498e6
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/ResultReceiverException.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: ResultReceiverException.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/03/04 16:47:57 $
+ * by $Author: davidwithers $
+ * Created on 05-May-2006
+ *****************************************************************/
+package org.biomart.martservice;
+
+/**
+ *
+ * @author David Withers
+ */
+public class ResultReceiverException extends Exception {
+ private static final long serialVersionUID = 7151337259555845771L;
+
+ /**
+ * Constructs a new exception with no detail message.
+ *
+ */
+ public ResultReceiverException() {
+ super();
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message
+ * the detail message
+ * @param cause
+ * the cause (a null value is permitted, and indicates that the
+ * cause is nonexistent or unknown)
+ */
+ public ResultReceiverException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message
+ * the detail message
+ */
+ public ResultReceiverException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause.
+ *
+ * @param cause
+ * the cause (a null value is permitted, and indicates that the
+ * cause is nonexistent or unknown)
+ */
+ public ResultReceiverException(Throwable cause) {
+ super(cause);
+ }
+
+}
[17/17] incubator-taverna-plugin-bioinformatics git commit:
org.apache.taverna.scufl2.* imports
Posted by st...@apache.org.
org.apache.taverna.scufl2.* imports
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/commit/87883d91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/tree/87883d91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/diff/87883d91
Branch: refs/heads/master
Commit: 87883d91b16dc39a033802ae1570deb51283e6c0
Parents: a87b415
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sat Feb 21 23:34:16 2015 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sat Feb 21 23:34:16 2015 +0000
----------------------------------------------------------------------
.../biomart/actions/BiomartActivityConfigurationAction.java | 2 +-
.../activities/biomart/actions/BiomartConfigurationPanel.java | 2 +-
.../biomart/servicedescriptions/BiomartServiceDescription.java | 2 +-
.../biomart/views/BiomartActivityContextualView.java | 2 +-
.../activities/biomart/views/BiomartActivityViewFactory.java | 2 +-
.../t2/biomart/views/TestBiomartActivityContextualView.java | 6 +++---
.../soaplab/actions/SoaplabActivityConfigurationAction.java | 2 +-
.../activities/soaplab/actions/SoaplabConfigurationPanel.java | 2 +-
.../soaplab/servicedescriptions/SoaplabServiceDescription.java | 2 +-
.../soaplab/views/SoaplabActivityContextualView.java | 4 ++--
.../activities/soaplab/views/SoaplabActivityViewFactory.java | 2 +-
.../soaplab/views/TestSoaplabActivityContextualView.java | 2 +-
12 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
index a0b51e7..ad290f0 100644
--- a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartActivityConfigurationAction.java
@@ -33,7 +33,7 @@ import net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationActi
import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
import uk.org.taverna.commons.services.ServiceRegistry;
import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
@SuppressWarnings("serial")
public class BiomartActivityConfigurationAction extends ActivityConfigurationAction {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
index 2b6f662..4d0a118 100644
--- a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/actions/BiomartConfigurationPanel.java
@@ -48,7 +48,7 @@ import org.jdom.output.XMLOutputter;
import uk.org.taverna.commons.services.ServiceRegistry;
import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
public class BiomartConfigurationPanel extends ActivityConfigurationPanel {
private static Logger logger = Logger.getLogger(BiomartConfigurationPanel.class);
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
index ca50019..7508b4d 100644
--- a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/servicedescriptions/BiomartServiceDescription.java
@@ -31,7 +31,7 @@ import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
-import uk.org.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.configurations.Configuration;
import com.fasterxml.jackson.databind.node.ObjectNode;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
index 87a2294..eacf193 100644
--- a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityContextualView.java
@@ -44,7 +44,7 @@ import org.jdom.input.SAXBuilder;
import uk.org.taverna.commons.services.ServiceRegistry;
import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
@SuppressWarnings("serial")
public class BiomartActivityContextualView extends HTMLBasedActivityContextualView {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
index ad8321a..4a866bc 100644
--- a/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
+++ b/taverna-biomart-activity-ui/src/main/java/net/sf/taverna/t2/activities/biomart/views/BiomartActivityViewFactory.java
@@ -33,7 +33,7 @@ import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
import uk.org.taverna.commons.services.ServiceRegistry;
import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
public class BiomartActivityViewFactory implements ContextualViewFactory<Activity> {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java b/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
index 04ad076..8ad6242 100644
--- a/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
+++ b/taverna-biomart-activity-ui/src/test/java/net/sf/taverna/t2/biomart/views/TestBiomartActivityContextualView.java
@@ -38,9 +38,9 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import uk.org.taverna.scufl2.api.activity.Activity;
-import uk.org.taverna.scufl2.api.configurations.Configuration;
-import uk.org.taverna.scufl2.api.profiles.Profile;
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.profiles.Profile;
import com.fasterxml.jackson.databind.node.ObjectNode;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
index 43b87f1..d4e85f9 100644
--- a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabActivityConfigurationAction.java
@@ -31,7 +31,7 @@ import net.sf.taverna.t2.workbench.edits.EditManager;
import net.sf.taverna.t2.workbench.file.FileManager;
import net.sf.taverna.t2.workbench.ui.actions.activity.ActivityConfigurationAction;
import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationDialog;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
public class SoaplabActivityConfigurationAction extends ActivityConfigurationAction {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
index 9b4b0c8..560562b 100644
--- a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/actions/SoaplabConfigurationPanel.java
@@ -34,7 +34,7 @@ import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ActivityConfigurationPanel;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
@SuppressWarnings("serial")
public class SoaplabConfigurationPanel extends ActivityConfigurationPanel {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
index 99a25b3..1d2a48b 100644
--- a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/servicedescriptions/SoaplabServiceDescription.java
@@ -8,7 +8,7 @@ import java.util.List;
import javax.swing.Icon;
import net.sf.taverna.t2.servicedescriptions.ServiceDescription;
-import uk.org.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.configurations.Configuration;
import com.fasterxml.jackson.databind.node.ObjectNode;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
index de51f23..6dbd2b0 100644
--- a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityContextualView.java
@@ -45,8 +45,8 @@ import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.log4j.Logger;
-import uk.org.taverna.scufl2.api.activity.Activity;
-import uk.org.taverna.scufl2.api.configurations.Configuration;
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.configurations.Configuration;
import com.fasterxml.jackson.databind.JsonNode;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
index 23e94d8..3b7986d 100644
--- a/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
+++ b/taverna-soaplab-activity-ui/src/main/java/net/sf/taverna/t2/activities/soaplab/views/SoaplabActivityViewFactory.java
@@ -31,7 +31,7 @@ import net.sf.taverna.t2.workbench.edits.EditManager;
import net.sf.taverna.t2.workbench.file.FileManager;
import net.sf.taverna.t2.workbench.ui.views.contextualviews.ContextualView;
import net.sf.taverna.t2.workbench.ui.views.contextualviews.activity.ContextualViewFactory;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
public class SoaplabActivityViewFactory implements ContextualViewFactory<Activity> {
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/87883d91/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
----------------------------------------------------------------------
diff --git a/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java b/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
index c4d683d..039cc18 100644
--- a/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
+++ b/taverna-soaplab-activity-ui/src/test/java/net/sf/taverna/t2/activities/soaplab/views/TestSoaplabActivityContextualView.java
@@ -29,7 +29,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import uk.org.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.scufl2.api.activity.Activity;
public class TestSoaplabActivityContextualView {
[11/17] incubator-taverna-plugin-bioinformatics git commit: Revert
"temporarily empty repository"
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MinimalLayout.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MinimalLayout.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MinimalLayout.java
new file mode 100644
index 0000000..153b982
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/MinimalLayout.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: MinimalLayout.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/06/27 12:49:48 $
+ * by $Author: davidwithers $
+ * Created on 26 Jun 2007
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.LayoutManager;
+
+/**
+ * A layout manager that lays out components, either horizontally or vertically,
+ * according to their minimum size.
+ *
+ * @author David Withers
+ */
+class MinimalLayout implements LayoutManager {
+ public static final int HORIZONTAL = 0;
+
+ public static final int VERTICAL = 1;
+
+ private static final int gap = 5;
+
+ private int type;
+
+ public MinimalLayout() {
+ type = HORIZONTAL;
+ }
+
+ public MinimalLayout(int type) {
+ this.type = type;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
+ */
+ public void removeLayoutComponent(Component comp) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
+ */
+ public void layoutContainer(Container parent) {
+ Insets insets = parent.getInsets();
+ int x = insets.left;
+ int y = insets.top;
+ if (type == HORIZONTAL) {
+ Component[] components = parent.getComponents();
+ for (int i = 0; i < components.length; i++) {
+ components[i].setLocation(x, y);
+ components[i].setSize(getSize(components[i]));
+ x = x + gap + components[i].getWidth();
+ }
+ } else {
+ Component[] components = parent.getComponents();
+ for (int i = 0; i < components.length; i++) {
+ components[i].setLocation(x, y);
+ components[i].setSize(getSize(components[i]));
+ y = y + gap + components[i].getHeight();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String,
+ * java.awt.Component)
+ */
+ public void addLayoutComponent(String name, Component comp) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
+ */
+ public Dimension minimumLayoutSize(Container parent) {
+ Insets insets = parent.getInsets();
+ Dimension minimumSize = new Dimension(insets.left, insets.top);
+ if (type == HORIZONTAL) {
+ int x = insets.left;
+ Component[] components = parent.getComponents();
+ for (int i = 0; i < components.length; i++) {
+ Dimension size = getSize(components[i]);
+ if (insets.top + size.height > minimumSize.height) {
+ minimumSize.height = insets.top + size.height;
+ }
+ minimumSize.width = x + size.width;
+ x = x + size.width + gap;
+ }
+ } else {
+ int y = insets.top;
+ Component[] components = parent.getComponents();
+ for (int i = 0; i < components.length; i++) {
+ Dimension size = getSize(components[i]);
+ if (insets.left + size.width > minimumSize.width) {
+ minimumSize.width = insets.left + size.width;
+ }
+ minimumSize.height = y + size.height;
+ y = y + size.height + gap;
+ }
+ }
+ minimumSize.width = minimumSize.width + insets.right;
+ minimumSize.height = minimumSize.height + insets.bottom;
+
+ return (minimumSize);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
+ */
+ public Dimension preferredLayoutSize(Container parent) {
+ return minimumLayoutSize(parent);
+ }
+
+ private Dimension getSize(Component component) {
+ return component.getPreferredSize();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryComponent.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryComponent.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryComponent.java
new file mode 100644
index 0000000..b976684
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryComponent.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryComponent.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/12/13 11:38:56 $
+ * by $Author: davidwithers $
+ * Created on 03-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.Vector;
+
+import javax.swing.AbstractButton;
+import javax.swing.JPanel;
+
+import org.biomart.martservice.MartDataset;
+import org.biomart.martservice.config.event.QueryComponentEvent;
+import org.biomart.martservice.config.event.QueryComponentListener;
+import org.ensembl.mart.lib.config.BaseNamedConfigurationObject;
+
+/**
+ * Abstract class for creating query configuration UI components.
+ *
+ * @author David Withers
+ */
+public abstract class QueryComponent extends JPanel {
+ public static final int ATTRIBUTE = 0;
+
+ public static final int FILTER = 1;
+
+ public static final int LINK = 2;
+
+ private Vector<QueryComponentListener> queryComponentListeners = new Vector<QueryComponentListener>();
+
+ private MartDataset dataset;
+
+ private String pointerDataset;
+
+ private String name;
+
+ private String value;
+
+ private BaseNamedConfigurationObject configObject;
+
+ protected AbstractButton selectorButton;
+
+ public abstract int getType();
+
+ /**
+ * Returns the dataset.
+ *
+ * @return the dataset.
+ */
+ public MartDataset getDataset() {
+ return dataset;
+ }
+
+ /**
+ * Sets the dataset.
+ *
+ * @param dataset
+ * the dataset to set.
+ */
+ public void setDataset(MartDataset dataset) {
+ this.dataset = dataset;
+ }
+
+ /**
+ * Returns the pointerDataset.
+ *
+ * @return the pointerDataset
+ */
+ public String getPointerDataset() {
+ return pointerDataset;
+ }
+
+ /**
+ * Sets the pointerDataset.
+ *
+ * @param pointerDataset the new pointerDataset
+ */
+ public void setPointerDataset(String pointerDataset) {
+ this.pointerDataset = pointerDataset;
+ }
+
+ /**
+ * Returns the name.
+ *
+ * @return the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name
+ * the name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getQualifiedName() {
+ return getDataset().getName() + "." + getName();
+ }
+
+ public String getOldQualifiedName() {
+ if (pointerDataset == null) {
+ return getDataset().getName() + "." + getName();
+ } else {
+ return pointerDataset + "." + getName();
+ }
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return the value.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * @param value
+ * the value to set.
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the configObject.
+ *
+ * @return the configObject
+ */
+ public BaseNamedConfigurationObject getConfigObject() {
+ return configObject;
+ }
+
+ /**
+ * Sets the configObject.
+ *
+ * @param configObject
+ * the configObject to set.
+ */
+ public void setConfigObject(BaseNamedConfigurationObject configObject) {
+ this.configObject = configObject;
+ }
+
+ /**
+ * Sets the selected state of this component.
+ *
+ * @param selected
+ * <code>true</code> if this component is selected,
+ * <code>false</code> otherwise
+ */
+ public void setSelected(boolean selected) {
+ if (selectorButton != null) {
+ selectorButton.setSelected(selected);
+ }
+ }
+
+ /**
+ * Sets the button used to select/deselect this QueryComponent.
+ *
+ * This function adds an ItemListener to the button and fires the
+ * appropriate QueryComponentEvent when the button is selected or
+ * deselected.
+ *
+ * @param button
+ * the button used to select/deselect this QueryComponent.
+ */
+ public void setSelectorButton(AbstractButton button) {
+ selectorButton = button;
+ button.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ if (getType() == ATTRIBUTE) {
+ fireAttributeAdded(new QueryComponentEvent(
+ QueryComponent.this, getName(), getDataset()));
+ } else {
+ fireFilterAdded(new QueryComponentEvent(
+ QueryComponent.this, getName(), getDataset()));
+ }
+ } else if (e.getStateChange() == ItemEvent.DESELECTED) {
+ if (getType() == ATTRIBUTE) {
+ fireAttributeRemoved(new QueryComponentEvent(
+ QueryComponent.this, getName(), getDataset()));
+ } else {
+ fireFilterRemoved(new QueryComponentEvent(
+ QueryComponent.this, getName(), getDataset()));
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Adds the specified query component listener to receive query component
+ * events. If <code>listener</code> is null, no exception is thrown and no
+ * action is performed.
+ *
+ * @param listener
+ * the query component listener
+ */
+ public void addQueryComponentListener(QueryComponentListener listener) {
+ queryComponentListeners.add(listener);
+ }
+
+ /**
+ * Removes the specified query component listener so that it no longer
+ * receives component query events. This method performs no function, nor
+ * does it throw an exception, if <code>listener</code> was not previously
+ * added to this component. If <code>listener</code> is null, no exception
+ * is thrown and no action is performed.
+ *
+ * @param listener
+ * the query component listener
+ */
+ public void removeQueryComponentListener(QueryComponentListener listener) {
+ queryComponentListeners.remove(listener);
+ }
+
+ /**
+ * Fires an attribute added event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireAttributeAdded(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.attributeAdded(event);
+ }
+ }
+
+ /**
+ * Fires an attribute removed event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireAttributeRemoved(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.attributeRemoved(event);
+ }
+ }
+
+ /**
+ * Fires an filter added event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireFilterAdded(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.filterAdded(event);
+ }
+ }
+
+ /**
+ * Fires an filter removed event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireFilterRemoved(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.filterRemoved(event);
+ }
+ }
+
+ /**
+ * Fires an filter changed event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireFilterChanged(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.filterChanged(event);
+ }
+ }
+
+ /**
+ * Fires an link added event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireLinkAdded(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.linkAdded(event);
+ }
+ }
+
+ /**
+ * Fires an link removed event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireLinkRemoved(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.linkRemoved(event);
+ }
+ }
+
+ /**
+ * Fires an link changed event.
+ *
+ * @param event the event to be fired
+ */
+ protected void fireLinkChanged(QueryComponentEvent event) {
+ for (QueryComponentListener listener : queryComponentListeners) {
+ listener.linkChanged(event);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryConfigUIFactory.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryConfigUIFactory.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryConfigUIFactory.java
new file mode 100644
index 0000000..d0a740a
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/config/ui/QueryConfigUIFactory.java
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryConfigUIFactory.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:08 $
+ * by $Author: davidwithers $
+ * Created on 04-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.config.ui;
+
+import java.awt.Component;
+
+import org.biomart.martservice.MartServiceException;
+import org.ensembl.mart.lib.config.AttributeCollection;
+import org.ensembl.mart.lib.config.AttributeDescription;
+import org.ensembl.mart.lib.config.AttributeGroup;
+import org.ensembl.mart.lib.config.AttributeList;
+import org.ensembl.mart.lib.config.AttributePage;
+import org.ensembl.mart.lib.config.FilterCollection;
+import org.ensembl.mart.lib.config.FilterDescription;
+import org.ensembl.mart.lib.config.FilterGroup;
+import org.ensembl.mart.lib.config.FilterPage;
+
+/**
+ * Interface for generating graphical components from <code>DatasetConfig</code>
+ * objects.
+ *
+ * @author David Withers
+ */
+public interface QueryConfigUIFactory {
+
+ public final static String SINGLE_SELECTION = "SINGLE";
+
+ public final static String MULTIPLE_SELECTION = "MULTIPLE";
+
+ public final static String LIST_SELECTION = "LIST";
+
+ /**
+ * Generates a <code>Component</code> for a <code>DatasetConfig</code>.
+ *
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getDatasetConfigUI() throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>AttributePage</code>.
+ *
+ * @param attributePages
+ * an array of <code>AttributePage</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributePagesUI(AttributePage[] attributePages,
+ Object data) throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an <code>AttributePage</code>.
+ *
+ * @param attributePage
+ * an <code>AttributePage</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributePageUI(AttributePage attributePage, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>AttributeGroup</code>.
+ *
+ * @param attributeGroups
+ * an array of <code>AttributeGroup</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeGroupsUI(AttributeGroup[] attributeGroups,
+ Object data) throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an <code>AttributeGroup</code>.
+ *
+ * @param attributeGroup
+ * an <code>AttributeGroup</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeGroupUI(AttributeGroup attributeGroup,
+ Object data) throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>AttributeCollection</code>.
+ *
+ * @param attributeCollections
+ * an array of <code>AttributeCollection</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeCollectionsUI(
+ AttributeCollection[] attributeCollections, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an
+ * <code>AttributeCollection</code>.
+ *
+ * @param attributeCollection
+ * an <code>AttributeCollection</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeCollectionUI(
+ AttributeCollection attributeCollection, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>AttributeDescription</code>.
+ *
+ * @param attributeDescriptions
+ * an array of <code>AttributeDescription</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeDescriptionsUI(
+ AttributeDescription[] attributeDescriptions, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an
+ * <code>AttributeDescription</code>.
+ *
+ * @param attributeDescription
+ * an <code>AttributeDescription</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeDescriptionUI(
+ AttributeDescription attributeDescription, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>AttributeList</code>.
+ *
+ * @param attributeLists
+ * an array of <code>AttributeList</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeListsUI(
+ AttributeList[] attributeLists, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an
+ * <code>AttributeList</code>.
+ *
+ * @param attributeList
+ * an <code>AttributeList</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getAttributeListUI(
+ AttributeList attributeList, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>FilterPage</code>.
+ *
+ * @param filterPages
+ * an array of <code>FilterPage</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterPagesUI(FilterPage[] filterPages, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for a <code>FilterPage</code>.
+ *
+ * @param filterPage
+ * a <code>FilterPage</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterPageUI(FilterPage filterPage, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>FilterGroup</code>.
+ *
+ * @param filterGroups
+ * an array of <code>FilterGroup</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterGroupsUI(FilterGroup[] filterGroups, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for a <code>FilterGroup</code>.
+ *
+ * @param filterGroup
+ * a <code>FilterGroup</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterGroupUI(FilterGroup filterGroup, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>FilterCollection</code>.
+ *
+ * @param filterCollections
+ * an array of <code>FilterCollection</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterCollectionsUI(
+ FilterCollection[] filterCollections, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for a <code>FilterCollection</code>.
+ *
+ * @param filterCollection
+ * a <code>FilterCollection</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterCollectionUI(FilterCollection filterCollection,
+ Object data) throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for an array of
+ * <code>FilterDescription</code>.
+ *
+ * @param filterDescriptions
+ * an array of <code>FilterDescription</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterDescriptionsUI(
+ FilterDescription[] filterDescriptions, Object data)
+ throws MartServiceException;
+
+ /**
+ * Generates a <code>Component</code> for a <code>FilterDescription</code>.
+ *
+ * @param filterDescription
+ * a <code>FilterDescription</code>
+ * @param data
+ * extra context information
+ * @return the generated <code>Component</code>
+ * @throws MartServiceException
+ * if the MartService returns an error or is unavailable
+ */
+ public Component getFilterDescriptionUI(
+ FilterDescription filterDescription, Object data)
+ throws MartServiceException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Attribute.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Attribute.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Attribute.java
new file mode 100644
index 0000000..7ec9932
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Attribute.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: Attribute.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/03/04 16:43:40 $
+ * by $Author: davidwithers $
+ * Created on 26-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+/**
+ * Class for creating attribute elements of mart queries.
+ *
+ * @author David Withers
+ */
+public class Attribute {
+ private String name;
+
+ private String attributes;
+
+ private int attributesCount;
+
+ private Dataset containingDataset;
+
+ /**
+ * Constructs an instance of an <code>Attribute</code> with the specified name.
+ *
+ * @param name
+ * the name of the <code>Attribute</code>; must not be <code>null</code>
+ */
+ public Attribute(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Parameter 'name' must not be null");
+ }
+ this.name = name;
+ }
+
+ /**
+ * Constructs an instance of an <code>Attribute</code> which is a copy of
+ * another <code>Attribute</code>.
+ *
+ * @param attribute
+ * the <code>Attribute</code> to copy; must not be <code>null</code>
+ */
+ public Attribute(Attribute attribute) {
+ if (attribute == null) {
+ throw new IllegalArgumentException("Parameter 'attribute' must not be null");
+ }
+ setName(attribute.getName());
+ setAttributes(attribute.getAttributes());
+ }
+
+ /**
+ * Returns the name of the Attribute.
+ *
+ * @return the name of the Attribute
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the Attribute.
+ *
+ * @param name
+ * the name of the Attribute; must not be <code>null</code>
+ */
+ public void setName(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Parameter 'name' must not be null");
+ }
+ this.name = name;
+ }
+
+ /**
+ * Returns the qualified name of this <code>Attribute</code>.
+ *
+ * The qualified name is <code>containingDatasetName.attributeName</code>
+ * or just <code>attributeName</code> if the <code>Attribute</code> is
+ * not in a <code>Dataset</code>.
+ *
+ * @return the qualified name of this <code>Attribute</code>
+ */
+ public String getQualifiedName() {
+ if (containingDataset == null) {
+ return name;
+ } else {
+ return containingDataset.getName() + "." + getName();
+ }
+ }
+
+ /**
+ * Returns the component attributes as a comma separated list.
+ *
+ * @return the attributes as a comma separated list or null if there are no component attributes
+ */
+ public String getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * Sets the attributes.
+ *
+ * @param attributes the new attributes
+ */
+ public void setAttributes(String attributes) {
+ this.attributes = attributes;
+ if (attributes == null) {
+ attributesCount = 0;
+ } else {
+ attributesCount = attributes.split(",").length;
+ }
+ }
+
+ /**
+ * Returns the number of component attributes.
+ *
+ * @return the number of component attributes
+ */
+ public int getAttributesCount() {
+ return attributesCount;
+ }
+
+ /**
+ * Returns the Dataset containing this Attribute or null if it is not in a
+ * Dataset.
+ *
+ * @return the Dataset containing this Attribute or null if it is not in a
+ * Dataset
+ */
+ public Dataset getContainingDataset() {
+ return containingDataset;
+ }
+
+ /**
+ * Sets the containing Dataset.
+ *
+ * @param dataset
+ * the containing Dataset
+ */
+ void setContainingDataset(Dataset dataset) {
+ this.containingDataset = dataset;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj != null) {
+ Attribute attribute = (Attribute) obj;
+ String qualifiedName = getQualifiedName();
+ if (qualifiedName == null) {
+ result = attribute.getQualifiedName() == null;
+ } else {
+ result = qualifiedName.equals(attribute.getQualifiedName());
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return getQualifiedName().hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Dataset.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Dataset.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Dataset.java
new file mode 100644
index 0000000..20ea68f
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Dataset.java
@@ -0,0 +1,309 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: Dataset.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/03 15:57:30 $
+ * by $Author: davidwithers $
+ * Created on 21-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Class for creating dataset elements of mart queries.
+ *
+ * @author David Withers
+ */
+public class Dataset {
+ private String name;
+
+ private List<Attribute> attributes = new ArrayList<Attribute>();
+
+ private List<Filter> filters = new ArrayList<Filter>();
+
+ private Query containingQuery;
+
+ /**
+ * Constructs an instance of a <code>Dataset</code> with the specified
+ * name.
+ *
+ * @param name
+ * the name of the <code>Dataset</code>
+ */
+ public Dataset(String name) {
+ setName(name);
+ }
+
+ /**
+ * Constructs an instance of a <code>Dataset</code> which is a deep copy
+ * of another <code>Dataset</code>.
+ *
+ * @param dataset
+ * the <code>Dataset</code> to copy
+ */
+ public Dataset(Dataset dataset) {
+ setName(dataset.getName());
+ for (Attribute attribute : dataset.getAttributes()) {
+ addAttribute(new Attribute(attribute));
+ }
+ for (Filter filter : dataset.getFilters()) {
+ addFilter(new Filter(filter));
+ }
+ }
+
+ /**
+ * Returns the name of the Dataset.
+ *
+ * @return the name of the Dataset.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name of the Dataset.
+ *
+ * @param name
+ * the new name for this Dataset.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns a List of the Attributes in this dataset.
+ *
+ * @return a List of the Attributes in this dataset
+ */
+ public List<Attribute> getAttributes() {
+ return new ArrayList<Attribute>(attributes);
+ }
+
+ /**
+ * Adds an Attribute to the dataset. The attribute's containing dataset will
+ * be set to this dataset. If this dataset is in a query an attribute added
+ * event will be fired.
+ *
+ * @param attribute
+ * the Attribute to add
+ * @return true if the Attribute is not already in the dataset
+ */
+ public boolean addAttribute(Attribute attribute) {
+ if (!attributes.contains(attribute)) {
+ attributes.add(attribute);
+ attribute.setContainingDataset(this);
+ if (containingQuery != null) {
+ containingQuery.fireAttributeAdded(attribute, this);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Adds an array of Attributes to the dataset.
+ *
+ * @param attributeArray
+ * the array of Attributes to add
+ */
+ public void addAttributes(Attribute[] attributeArray) {
+ for (int i = 0; i < attributeArray.length; i++) {
+ addAttribute(attributeArray[i]);
+ }
+ }
+
+ /**
+ * Returns true if attribute is in the dataset.
+ *
+ * @param attribute
+ * @return true if attribute is in the dataset.
+ */
+ public boolean hasAttribute(Attribute attribute) {
+ return attributes.contains(attribute);
+ }
+
+ /**
+ * Returns true if the dataset contains any Attributes.
+ *
+ * @return true if the dataset contains any Attributes
+ */
+ public boolean hasAttributes() {
+ return attributes.size() > 0;
+ }
+
+ /**
+ * Removes an Attribute from the dataset.
+ *
+ * If the attribute is contained in this dataset:
+ * <ul>
+ * <li>The attribute's containing dataset will be set to null.
+ * <li>If this dataset is in a query an attribute removed event will be fired.
+ *
+ * @param attribute
+ * the attribute to remove
+ * @return true if the attribute is removed
+ */
+ public boolean removeAttribute(Attribute attribute) {
+ if (attributes.remove(attribute)) {
+ attribute.setContainingDataset(null);
+ if (containingQuery != null) {
+ containingQuery.fireAttributeRemoved(attribute, this);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Removes all the Attributes from this dataset.
+ */
+ public void removeAllAttributes() {
+ for (Attribute attribute : getAttributes()) {
+ removeAttribute(attribute);
+ }
+ }
+
+ /**
+ * Returns a List of the Filters in this dataset.
+ *
+ * @return a List of the Filters in this dataset
+ */
+ public List<Filter> getFilters() {
+ return new ArrayList<Filter>(filters);
+ }
+
+ /**
+ * Adds a Filter to the dataset. The filter's containing dataset will be set
+ * to this dataset. If this dataset is in a query a filter added event will
+ * be fired.
+ *
+ * @param filter
+ * the Filter to add
+ * @return true if the Filter is not already in the dataset
+ */
+ public boolean addFilter(Filter filter) {
+ if (!filters.contains(filter)) {
+ filters.add(filter);
+ filter.setContainingDataset(this);
+ if (containingQuery != null) {
+ containingQuery.fireFilterAdded(filter, this);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Adds an array of Filters to the dataset.
+ *
+ * @param filterArray
+ * the array of Filters to add
+ */
+ public void addFilters(Filter[] filterArray) {
+ for (int i = 0; i < filterArray.length; i++) {
+ addFilter(filterArray[i]);
+ }
+ }
+
+ /**
+ * Returns true if filter is in the dataset.
+ *
+ * @param filter
+ * @return true if filter is in the dataset
+ */
+ public boolean hasFilter(Filter filter) {
+ return filters.contains(filter);
+ }
+
+ /**
+ * Returns true if the dataset contains any filters.
+ *
+ * @return true if the dataset contains any filters
+ */
+ public boolean hasFilters() {
+ return filters.size() > 0;
+ }
+
+ /**
+ * Removes an Filter from the dataset.
+ *
+ * If the filter is contained in this dataset:
+ * <ul>
+ * <li>The filter's containing dataset will be set to null.
+ * <li>If this dataset is in a query an attribute removed event will be fired.
+ *
+ * @param filter
+ * the filter to remove
+ * @return true if the filter is removed
+ */
+ public boolean removeFilter(Filter filter) {
+ if (filters.remove(filter)) {
+ filter.setContainingDataset(null);
+ if (containingQuery != null) {
+ containingQuery.fireFilterRemoved(filter, this);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Removes all the filters from the dataset.
+ */
+ public void removeAllFilters() {
+ for (Filter filter : getFilters()) {
+ removeFilter(filter);
+ }
+ }
+
+ /**
+ * Returns the containingQuery.
+ *
+ * @return the containingQuery.
+ */
+ public Query getContainingQuery() {
+ return containingQuery;
+ }
+
+ /**
+ * Sets the containingQuery.
+ *
+ * @param containingQuery
+ * the containingQuery to set.
+ */
+ void setContainingQuery(Query containingQuery) {
+ this.containingQuery = containingQuery;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Filter.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Filter.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Filter.java
new file mode 100644
index 0000000..1c088d0
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Filter.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: Filter.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:09 $
+ * by $Author: davidwithers $
+ * Created on 26-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+/**
+ * Class for creating filter elements of mart queries.
+ *
+ * @author David Withers
+ */
+public class Filter {
+ private String name;
+
+ private String value;
+
+ private boolean booleanFilter;
+
+ private boolean listFilter;
+
+ private Dataset containingDataset;
+
+ /**
+ * Constructs an instance of a <code>Filter</code> with the specified name.
+ *
+ * @param name
+ * the name of the <code>Filter</code>; must not be <code>null</code>
+ */
+ public Filter(String name) {
+ this(name, null);
+ }
+
+ /**
+ * Constructs a instance of a <code>Filter</code> with the specified name
+ * and value.
+ *
+ * @param name
+ * the name of the <code>Filter</code>; must not be <code>null</code>
+ * @param value
+ * the value of the <code>Filter</code>
+ */
+ public Filter(String name, String value) {
+ this(name, value, false);
+ }
+
+ /**
+ * Constructs a instance of a <code>Filter</code> with the specified name
+ * and value, and sets a flag to indicate if this is a boolean
+ * <code>Filter</code>.
+ *
+ * @param name
+ * the name of the <code>Filter</code>; must not be <code>null</code>
+ * @param value
+ * the value of the <code>Filter</code>
+ * @param booleanFilter
+ */
+ public Filter(String name, String value, boolean booleanFilter) {
+ if (name == null) {
+ throw new IllegalArgumentException("Parameter 'name' must not be null");
+ }
+ this.name = name;
+ this.value = value;
+ this.booleanFilter = booleanFilter;
+ }
+
+ /**
+ * Constructs an instance of a <code>Filter</code> which is a copy of
+ * another <code>Filter</code>.
+ *
+ * @param filter
+ * the <code>Filter</code> to copy; must not be <code>null</code>
+ */
+ public Filter(Filter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("Parameter 'filter' must not be null");
+ }
+ this.name = filter.name;
+ this.value = filter.value;
+ this.booleanFilter = filter.booleanFilter;
+ }
+
+ /**
+ * Returns the name of the Filter.
+ *
+ * @return the name of the Filter
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the Filter.
+ *
+ * @param name
+ * the name of the Filter; must not be <code>null</code>
+ */
+ public void setName(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Parameter 'name' must not be null");
+ }
+ this.name = name;
+ }
+
+ /**
+ * Returns the qualified name of this <code>Filter</code>.
+ *
+ * The qualified name is <code>containingDatasetName.filterName</code> or
+ * just <code>attributeName</code> if the <code>Filter</code> is not in
+ * a <code>Dataset</code>.
+ *
+ * @return the qualified name of this <code>Filter</code>.
+ */
+ public String getQualifiedName() {
+ if (containingDataset == null) {
+ return name;
+ } else {
+ return containingDataset.getName() + "." + getName();
+ }
+ }
+
+ /**
+ * Returns the <code>Dataset</code> containing this <code>Filter</code>
+ * or null if it is not in a <code>Dataset</code>.
+ *
+ * @return the <code>Dataset</code> containing this <code>Filter</code>
+ * or null if it is not in a <code>Dataset</code>
+ */
+ public Dataset getContainingDataset() {
+ return containingDataset;
+ }
+
+ /**
+ * Sets the containing <code>Dataset</code>.
+ *
+ * @param dataset
+ * the containing <code>Dataset</code>
+ */
+ void setContainingDataset(Dataset dataset) {
+ this.containingDataset = dataset;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return the value.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * @param value
+ * the value to set.
+ */
+ public void setValue(String value) {
+ boolean valueChanged = false;
+ if (this.value == null) {
+ if (value != null) {
+ this.value = value;
+ valueChanged = true;
+ }
+ } else if (!this.value.equals(value)) {
+ this.value = value;
+ valueChanged = true;
+ }
+ if (valueChanged) {
+ if (containingDataset != null) {
+ if (containingDataset.getContainingQuery() != null) {
+ containingDataset.getContainingQuery().fireFilterChanged(
+ this, containingDataset);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if this is a boolean filter.
+ *
+ * @return <code>true</code> if this is a boolean filter.
+ */
+ public boolean isBoolean() {
+ return booleanFilter;
+ }
+
+ /**
+ * Sets the booleanFilter flag.
+ *
+ * @param booleanFilter
+ */
+ public void setBoolean(boolean booleanFilter) {
+ this.booleanFilter = booleanFilter;
+ }
+
+ /**
+ * Returns <code>true</code> if this is a list filter.
+ *
+ * @return <code>true</code> if this is a list filter.
+ */
+ public boolean isList() {
+ return listFilter;
+ }
+
+ /**
+ * Sets the listFilter flag.
+ *
+ * @param listFilter
+ */
+ public void setList(boolean listFilter) {
+ this.listFilter = listFilter;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Link.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Link.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Link.java
new file mode 100644
index 0000000..721428c
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Link.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: Link.java,v $
+ * Revision $Revision: 1.1 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/01/31 14:12:09 $
+ * by $Author: davidwithers $
+ * Created on 26-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+/**
+ * Class for creating link elements of mart queries.
+ *
+ * @author David Withers
+ */
+public class Link {
+ private String source;
+
+ private String target;
+
+ private String defaultLink;
+
+ private Query containingQuery;
+
+ /**
+ * Constructs an instance of a <code>Link</code>.
+ *
+ * @param source
+ * the source dataset of the <code>Link</code>
+ * @param target
+ * the target dataset of the <code>Link</code>
+ * @param defaultLink
+ * the ID the links the datasets
+ */
+ public Link(String source, String target, String defaultLink) {
+ this.source = source;
+ this.target = target;
+ this.defaultLink = defaultLink;
+ }
+
+ /**
+ * Constructs an instance of a <code>Link</code> which is a copy of
+ * another <code>Link</code>.
+ *
+ * @param filter
+ * the <code>Link</code> to copy
+ */
+ public Link(Link link) {
+ this.source = link.source;
+ this.target = link.target;
+ this.defaultLink = link.defaultLink;
+ }
+
+ /**
+ * Returns the defaultLink.
+ *
+ * @return the defaultLink.
+ */
+ public String getDefaultLink() {
+ return defaultLink;
+ }
+
+ /**
+ * @param defaultLink
+ * the defaultLink to set.
+ */
+ public void setDefaultLink(String defaultLink) {
+ this.defaultLink = defaultLink;
+ }
+
+ /**
+ * Returns the source dataset.
+ *
+ * @return the source dataset.
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the source dataset.
+ *
+ * @param source
+ * the source dataset to set.
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ /**
+ * Returns the target dataset.
+ *
+ * @return the target dataset.
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the target dataset.
+ *
+ * @param target
+ * the target dataset to set.
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Returns the containingQuery.
+ *
+ * @return the containingQuery.
+ */
+ public Query getContainingQuery() {
+ return containingQuery;
+ }
+
+ /**
+ * Sets the containingQuery.
+ *
+ * @param containingQuery
+ * the containingQuery to set.
+ */
+ void setContainingQuery(Query containingQuery) {
+ this.containingQuery = containingQuery;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ boolean result = false;
+ if (obj != null) {
+ Link link = (Link) obj;
+ result = ((source == null && link.source == null) || source
+ .equals(link.source))
+ && ((target == null && link.target == null) || target
+ .equals(link.target))
+ && ((defaultLink == null && link.defaultLink == null) || defaultLink
+ .equals(link.defaultLink));
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return source.hashCode() + target.hashCode() + defaultLink.hashCode();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Query.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Query.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Query.java
new file mode 100644
index 0000000..c7c9f20
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/Query.java
@@ -0,0 +1,555 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: Query.java,v $
+ * Revision $Revision: 1.4 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/03 15:57:30 $
+ * by $Author: davidwithers $
+ * Created on 03-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.biomart.martservice.MartServiceException;
+
+/**
+ * Class for creating mart queries.
+ *
+ * @author David Withers
+ */
+public class Query {
+ private String virtualSchemaName;
+
+ private int count;
+
+ private int uniqueRows;
+
+ private String softwareVersion;
+
+ private String formatter;
+
+ private String requestId;
+
+ private List<Dataset> datasets = new ArrayList<Dataset>();
+
+ private Map<String, Dataset> datasetMap = new HashMap<String, Dataset>();
+
+ private Set<Link> links = new HashSet<Link>();
+
+ private Map<String, Link> linkSourceMap = new HashMap<String, Link>();
+
+ private List<QueryListener> listeners = new ArrayList<QueryListener>();
+
+ /**
+ * Constructs an instance of a <code>Query</code> with the specified
+ * <code>virtualSchemaName</code> and a <code>count</code> of 0.
+ *
+ * @param virtualSchemaName
+ */
+ public Query(String virtualSchemaName) {
+ this(virtualSchemaName, 0);
+ }
+
+ /**
+ * Constructs an instance of a <code>Query</code> with the specified
+ * <code>virtualSchemaName</code> and <code>count</code>.
+ *
+ * @param virtualSchemaName
+ * @param count
+ */
+ public Query(String virtualSchemaName, int count) {
+ setVirtualSchemaName(virtualSchemaName);
+ setCount(count);
+ }
+
+ /**
+ * Constructs an instance of a <code>Query</code> with the specified
+ * <code>virtualSchemaName</code>, <code>softwareVersion</code> and
+ * <code>requestId</code>.
+ *
+ * @param virtualSchemaName
+ * @param softwareVersion
+ * @param requestId
+ */
+ public Query(String virtualSchemaName, String softwareVersion,
+ String requestId) {
+ this(virtualSchemaName, 0, softwareVersion, requestId);
+ }
+
+ /**
+ * Constructs an instance of a <code>Query</code> with the specified
+ * <code>virtualSchemaName</code>, <code>count</code> and
+ * <code>softwareVersion</code>.
+ *
+ * @param virtualSchemaName
+ * @param count
+ * @param softwareVersion
+ */
+ public Query(String virtualSchemaName, int count, String softwareVersion) {
+ this(virtualSchemaName, count, softwareVersion, null);
+ }
+
+ /**
+ * Constructs an instance of a <code>Query</code> with the specified
+ * <code>virtualSchemaName</code>, <code>count</code>,
+ * <code>softwareVersion</code> and <code>requestId</code>.
+ *
+ * @param virtualSchemaName
+ * @param count
+ * @param softwareVersion
+ * @param requestId
+ */
+ public Query(String virtualSchemaName, int count, String softwareVersion,
+ String requestId) {
+ setVirtualSchemaName(virtualSchemaName);
+ setCount(count);
+ setSoftwareVersion(softwareVersion);
+ setRequestId(requestId);
+ }
+
+ /**
+ * Constructs an instance of a <code>Query</code> which is a deep copy of
+ * another <code>Query</code>.
+ *
+ * @param query
+ * the <code>Query</code> to copy
+ * @throws MartServiceException
+ */
+ public Query(Query query) {
+ setVirtualSchemaName(query.virtualSchemaName);
+ setCount(query.count);
+ setUniqueRows(query.uniqueRows);
+ setSoftwareVersion(query.softwareVersion);
+ setFormatter(query.formatter);
+ setRequestId(query.requestId);
+ for (Dataset dataset : query.getDatasets()) {
+ addDataset(new Dataset(dataset));
+ }
+ for (Link link : query.getLinks()) {
+ addLink(new Link(link));
+ }
+ }
+
+ /**
+ * Returns the virtualSchema.
+ *
+ * @return the virtualSchema.
+ */
+ public String getVirtualSchemaName() {
+ return virtualSchemaName;
+ }
+
+ /**
+ * Sets the virtualSchema.
+ *
+ * @param virtualSchemaName
+ * the virtualSchema to set.
+ */
+ public void setVirtualSchemaName(String virtualSchemaName) {
+ this.virtualSchemaName = virtualSchemaName;
+ }
+
+ /**
+ * Returns the count.
+ *
+ * @return the count.
+ */
+ public int getCount() {
+ return count;
+ }
+
+ /**
+ * Sets the count.
+ *
+ * @param count
+ * the count to set.
+ */
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ /**
+ * Returns the uniqueRows query attribute
+ *
+ * @return the uniqueRows query attribute
+ */
+ public int getUniqueRows() {
+ return uniqueRows;
+ }
+
+ /**
+ * Sets the uniqueRows query attribute.
+ *
+ * Valid values are 0 or 1.
+ *
+ * @param uniqueRows value for the uniqueRows query attribute
+ */
+ public void setUniqueRows(int uniqueRows) {
+ this.uniqueRows = uniqueRows;
+ }
+
+ /**
+ * Returns the softwareVersion.
+ *
+ * @return the softwareVersion
+ */
+ public String getSoftwareVersion() {
+ return softwareVersion;
+ }
+
+ /**
+ * Sets the softwareVersion.
+ *
+ * @param softwareVersion
+ * the new softwareVersion
+ */
+ public void setSoftwareVersion(String softwareVersion) {
+ this.softwareVersion = softwareVersion;
+ }
+
+ /**
+ * Returns the formatter.
+ *
+ * @return the formatter
+ */
+ public String getFormatter() {
+ return formatter;
+ }
+
+ /**
+ * Sets the formatter.
+ *
+ * @param formatter the new formatter
+ */
+ public void setFormatter(String formatter) {
+ if (this.formatter == null) {
+ if (formatter != null) {
+ this.formatter = formatter;
+ fireFormatterAdded(formatter);
+ }
+ } else if (!this.formatter.equals(formatter)) {
+ if (formatter == null) {
+ String removedFormatter = this.formatter;
+ this.formatter = formatter;
+ fireFormatterRemoved(removedFormatter);
+ } else {
+ this.formatter = formatter;
+ fireFormatterChanged(formatter);
+ }
+ }
+ }
+
+ /**
+ * Returns the requestId.
+ *
+ * @return the requestId
+ */
+ public String getRequestId() {
+ return requestId;
+ }
+
+ /**
+ * Sets the requestId.
+ *
+ * @param requestId
+ * the new requestId
+ */
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+
+ /**
+ * Adds a Dataset to the Query.
+ *
+ * The Dataset is added at the end of the list of Datasets.
+ *
+ * @param dataset
+ * the Dataset to add
+ */
+ public void addDataset(Dataset dataset) {
+ addDataset(datasets.size(), dataset);
+ }
+
+ /**
+ * Adds a Dataset to the Query at the specified position.
+ *
+ * @param index
+ * the position to add the Dataset
+ * @param dataset
+ * the Dataset to add
+ */
+ public void addDataset(int index, Dataset dataset) {
+ datasets.add(index, dataset);
+ datasetMap.put(dataset.getName(), dataset);
+ if (dataset.getContainingQuery() != null) {
+ dataset.getContainingQuery().removeDataset(dataset);
+ }
+ dataset.setContainingQuery(this);
+ }
+
+ /**
+ * Removes a Dataset from the Query.
+ *
+ * @param dataset
+ * the Dataset to remove
+ */
+ public void removeDataset(Dataset dataset) {
+ datasets.remove(dataset);
+ datasetMap.remove(dataset.getName());
+ dataset.setContainingQuery(null);
+ }
+
+ /**
+ * Removes all the Datasets from the Query.
+ */
+ public void removeAllDatasets() {
+ for (Dataset dataset : datasets) {
+ dataset.setContainingQuery(null);
+ }
+ datasets.clear();
+ datasetMap.clear();
+ }
+
+ /**
+ * Returns the Datasets that this Query contains.
+ *
+ * @return the Datasets that this Query contains.
+ */
+ public List<Dataset> getDatasets() {
+ return new ArrayList<Dataset>(datasets);
+ }
+
+ /**
+ * Returns a Dataset with the given datasetName. If the Query has no Dataset
+ * with the given datasetName null is returned.
+ *
+ * @param datasetName
+ * @return a Dataset with the given datasetName
+ */
+ public Dataset getDataset(String datasetName) {
+ return (Dataset) datasetMap.get(datasetName);
+ }
+
+ /**
+ * Returns true if this Query contains a Dataset with the name
+ * <code>datasetName</code>.
+ *
+ * @param datasetName
+ * @return true if this Query contains a Dataset with the name
+ * <code>datasetName</code>.
+ */
+ public boolean containsDataset(String datasetName) {
+ return datasetMap.containsKey(datasetName);
+ }
+
+ /**
+ * Adds a Link to the Query.
+ *
+ * @param link
+ * the Link to add
+ */
+ public void addLink(Link link) {
+ links.add(link);
+ linkSourceMap.put(link.getSource(), link);
+ if (link.getContainingQuery() != null) {
+ link.getContainingQuery().removeLink(link);
+ }
+ link.setContainingQuery(this);
+ }
+
+ /**
+ * Removes a link from the Query
+ *
+ * @param link
+ * the Link to remove
+ */
+ public void removeLink(Link link) {
+ links.remove(link);
+ linkSourceMap.remove(link.getSource());
+ link.setContainingQuery(null);
+ }
+
+ /**
+ * Returns the Links that this Query contains.
+ *
+ * @return the Links that this Query contains.
+ */
+ public Set<Link> getLinks() {
+ return new HashSet<Link>(links);
+ }
+
+ /**
+ * Returns a Link with the given source. If the Query has no Link with the
+ * given source null is returned.
+ *
+ * @param source
+ * the source of the link
+ * @return a Link with the given source
+ */
+ public Link getLink(String source) {
+ return (Link) linkSourceMap.get(source);
+ }
+
+ /**
+ * Returns true if this Query contains a Link with the same source.
+ *
+ * @param source
+ * the source of the link
+ * @return true if this Query contains a Link with the same source.
+ */
+ public boolean containsLink(String source) {
+ return linkSourceMap.containsKey(source);
+ }
+
+ /**
+ * Returns a List of Links with the given target. If the Query has no Link
+ * with the given target an empty List is returned.
+ *
+ * @param target
+ * the target of the link
+ * @return a Link with the given target
+ */
+ public Set<Link> getLinks(String target) {
+ Set<Link> result = new HashSet<Link>();
+ Set<Link> links = getLinks();
+ for (Link link: links) {
+ if (link.getTarget().equals(target)) {
+ result.add(link);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns all the Attributes from all the Datasets in this Query.
+ *
+ * @return all the Attributes from all the Datasets in this Query.
+ */
+ public List<Attribute> getAttributes() {
+ List<Attribute> attributes = new ArrayList<Attribute>();
+ for (Dataset dataset : datasets) {
+ attributes.addAll(dataset.getAttributes());
+ }
+ return attributes;
+ }
+
+ /**
+ * Returns all the Filters from all the Datasets in this Query.
+ *
+ * @return all the Filters from all the Datasets in this Query.
+ */
+ public List<Filter> getFilters() {
+ List<Filter> filters = new ArrayList<Filter>();
+ for (Dataset dataset : datasets) {
+ filters.addAll(dataset.getFilters());
+ }
+ return filters;
+ }
+
+ /**
+ * Adds the specified query listener to receive query events. If
+ * <code>listener</code> is null, no exception is thrown and no action is
+ * performed.
+ *
+ * @param listener
+ * the query listener
+ */
+ public void addQueryListener(QueryListener listener) {
+ if (listener != null) {
+ listeners.add(listener);
+ }
+ }
+
+ /**
+ * Removes the specified query listener so that it no longer receives query
+ * events. This method performs no function, nor does it throw an exception,
+ * if <code>listener</code> was not previously added to this component. If
+ * <code>listener</code> is null, no exception is thrown and no action is
+ * performed.
+ *
+ * @param listener
+ * the query listener
+ */
+ public void removeQueryListener(QueryListener listener) {
+ listeners.remove(listener);
+ }
+
+ void fireAttributeAdded(Attribute attribute, Dataset dataset) {
+ for (QueryListener listener : listeners) {
+ listener.attributeAdded(attribute, dataset);
+ }
+ }
+
+ void fireAttributeRemoved(Attribute attribute, Dataset dataset) {
+ for (QueryListener listener : listeners) {
+ listener.attributeRemoved(attribute, dataset);
+ }
+ }
+
+ void fireFilterAdded(Filter filter, Dataset dataset) {
+ for (QueryListener listener : listeners) {
+ listener.filterAdded(filter, dataset);
+ }
+ }
+
+ void fireFilterRemoved(Filter filter, Dataset dataset) {
+ for (QueryListener listener : listeners) {
+ listener.filterRemoved(filter, dataset);
+ }
+ }
+
+ void fireFilterChanged(Filter filter, Dataset dataset) {
+ for (QueryListener listener : listeners) {
+ listener.filterChanged(filter, dataset);
+ }
+ }
+
+ void fireFormatterAdded(String formatter) {
+ for (QueryListener listener : listeners) {
+ listener.formatterAdded(formatter);
+ }
+ }
+
+ void fireFormatterRemoved(String formatter) {
+ for (QueryListener listener : listeners) {
+ listener.formatterRemoved(formatter);
+ }
+ }
+
+ void fireFormatterChanged(String formatter) {
+ for (QueryListener listener : listeners) {
+ listener.formatterChanged(formatter);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryListener.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryListener.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryListener.java
new file mode 100644
index 0000000..9f10f45
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryListener.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryListener.java,v $
+ * Revision $Revision: 1.2 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2007/10/03 15:57:30 $
+ * by $Author: davidwithers $
+ * Created on 03-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+/**
+ * The listener interface for receiving Query events.
+ *
+ * @author David Withers
+ */
+public interface QueryListener {
+
+ /**
+ * Invoked when an <code>Attribute</code> is added to a <code>Query</code>.
+ *
+ * @param attribute
+ * the <code>Attribute</code> added.
+ */
+ public void attributeAdded(Attribute attribute, Dataset dataset);
+
+ /**
+ * Invoked when an <code>Attribute</code> is removed from a
+ * <code>Query</code>.
+ *
+ * @param attribute
+ * the <code>Attribute</code> removed.
+ */
+ public void attributeRemoved(Attribute attribute, Dataset dataset);
+
+ /**
+ * Invoked when a <code>Filter</code> is added to a <code>Query</code>.
+ *
+ * @param filter
+ * the <code>Filter</code> added.
+ */
+ public void filterAdded(Filter filter, Dataset dataset);
+
+ /**
+ * Invoked when a <code>Filter</code> is removed from a <code>Query</code>.
+ *
+ * @param filter
+ * the <code>Filter</code> removed.
+ */
+ public void filterRemoved(Filter filter, Dataset dataset);
+
+ /**
+ * Invoked when the value of a <code>Filter</code> is changed.
+ *
+ * @param filter
+ * the <code>Filter</code> whose value has changed.
+ */
+ public void filterChanged(Filter filter, Dataset dataset);
+
+ /**
+ * Invoked when a formatter is added to a <code>Query</code>.
+ *
+ * @param formatter
+ * the formatter added.
+ */
+ public void formatterAdded(String formatter);
+
+ /**
+ * Invoked when a formatter is removed from a <code>Query</code>.
+ *
+ * @param formatter
+ * the formatter removed.
+ */
+ public void formatterRemoved(String formatter);
+
+ /**
+ * Invoked when the value of the formatter is changed.
+ *
+ * @param filter
+ * the new value of the formatter.
+ */
+ public void formatterChanged(String formatter);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryXMLHandler.java
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryXMLHandler.java b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryXMLHandler.java
new file mode 100644
index 0000000..13c7791
--- /dev/null
+++ b/taverna-biomart-martservice/src/main/java/org/biomart/martservice/query/QueryXMLHandler.java
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2003 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate. Authorship
+ * of the modifications may be determined from the ChangeLog placed at
+ * the end of this file.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ ****************************************************************
+ * Source code information
+ * -----------------------
+ * Filename $RCSfile: QueryXMLHandler.java,v $
+ * Revision $Revision: 1.6 $
+ * Release status $State: Exp $
+ * Last modified on $Date: 2008/03/04 16:45:18 $
+ * by $Author: davidwithers $
+ * Created on 28-Apr-2006
+ *****************************************************************/
+package org.biomart.martservice.query;
+
+import java.util.List;
+
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+/**
+ * Utility class for serializing <code>Query</code> classes to XML.
+ *
+ * @author David Withers
+ */
+public class QueryXMLHandler {
+ public static final String QUERY_ELEMENT = "Query";
+
+ public static final String DATASET_ELEMENT = "Dataset";
+
+ public static final String ATTRIBUTE_ELEMENT = "Attribute";
+
+ public static final String FILTER_ELEMENT = "Filter";
+
+ public static final String LINK_ELEMENT = "Links";
+
+ public static final String ATTRIBUTES_ATTRIBUTE = "attributes";
+
+ public static final String NAME_ATTRIBUTE = "name";
+
+ public static final String COUNT_ATTRIBUTE = "count";
+
+ public static final String UNIQUE_ROWS_ATTRIBUTE = "uniqueRows";
+
+ public static final String VERSION_ATTRIBUTE = "softwareVersion";
+
+ public static final String FORMATTER_ATTRIBUTE = "formatter";
+
+ public static final String HEADER_ATTRIBUTE = "header";
+
+ public static final String REQUEST_ID_ATTRIBUTE = "requestId";
+
+ public static final String SCHEMA_ATTRIBUTE = "virtualSchemaName";
+
+ /**
+ * Converts a <code>Query</code> to an XML element.
+ *
+ * @param query
+ * the <code>Query</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>Query</code>
+ */
+ public static Element queryToElement(Query query, Namespace namespace) {
+ Element queryElement = new Element(QUERY_ELEMENT, namespace);
+ String virtualSchemaName = query.getVirtualSchemaName();
+ if (virtualSchemaName == null) {
+ queryElement.setAttribute(SCHEMA_ATTRIBUTE, "default");
+ } else {
+ queryElement.setAttribute(SCHEMA_ATTRIBUTE, virtualSchemaName);
+ }
+ queryElement.setAttribute(COUNT_ATTRIBUTE, String.valueOf(query.getCount()));
+ queryElement.setAttribute(UNIQUE_ROWS_ATTRIBUTE, String.valueOf(query.getUniqueRows()));
+ String softwareVersion = query.getSoftwareVersion();
+ if (softwareVersion != null) {
+ queryElement.setAttribute(VERSION_ATTRIBUTE, softwareVersion);
+ }
+ String formatter = query.getFormatter();
+ if (formatter != null) {
+ queryElement.setAttribute(FORMATTER_ATTRIBUTE, formatter);
+ queryElement.setAttribute(HEADER_ATTRIBUTE, "1");
+ }
+ String requestId = query.getRequestId();
+ if (requestId != null) {
+ queryElement.setAttribute(REQUEST_ID_ATTRIBUTE, requestId);
+ }
+ for (Dataset dataset : query.getDatasets()) {
+ queryElement.addContent(datasetToElement(dataset, namespace));
+ }
+ for (Link link : query.getLinks()) {
+ queryElement.addContent(linkToElement(link, namespace));
+ }
+
+ return queryElement;
+ }
+
+ /**
+ * Converts a <code>Dataset</code> to an XML element.
+ *
+ * @param dataset
+ * the <code>Dataset</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>Dataset</code>
+ */
+ public static Element datasetToElement(Dataset dataset, Namespace namespace) {
+ Element datasetElement = new Element(DATASET_ELEMENT, namespace);
+ datasetElement.setAttribute(NAME_ATTRIBUTE, dataset.getName());
+
+ for (Attribute attribute : dataset.getAttributes()) {
+ datasetElement.addContent(attributeToElement(attribute, namespace));
+ }
+
+ for (Filter filter : dataset.getFilters()) {
+ datasetElement.addContent(filterToElement(filter, namespace));
+ }
+
+ return datasetElement;
+ }
+
+ /**
+ * Converts a <code>Link</code> to an XML element.
+ *
+ * @param link
+ * the <code>Link</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>Link</code>
+ */
+ public static Element linkToElement(Link link, Namespace namespace) {
+ Element linkElement = new Element(LINK_ELEMENT, namespace);
+ linkElement.setAttribute("source", link.getSource());
+ linkElement.setAttribute("target", link.getTarget());
+ linkElement.setAttribute("defaultLink", link.getDefaultLink());
+ return linkElement;
+ }
+
+ /**
+ * Converts an <code>Attribute</code> to an XML element.
+ *
+ * @param attribute
+ * the <code>Attribute</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>Attribute</code>
+ */
+ public static Element attributeToElement(Attribute attribute,
+ Namespace namespace) {
+ Element attributeElement = new Element(ATTRIBUTE_ELEMENT, namespace);
+ attributeElement.setAttribute(NAME_ATTRIBUTE, attribute.getName());
+ String attributes = attribute.getAttributes();
+ if (attributes != null) {
+ attributeElement.setAttribute(ATTRIBUTES_ATTRIBUTE, attributes);
+ }
+ return attributeElement;
+ }
+
+ /**
+ * Converts a <code>Filter</code> to an XML element.
+ *
+ * @param filter
+ * the <code>Filter</code> to serialize
+ * @param namespace
+ * the <code>Namespace</code> to use when constructing the
+ * <code>Element</code>
+ * @return an XML serialization of the <code>Filter</code>
+ */
+ public static Element filterToElement(Filter filter, Namespace namespace) {
+ Element filterElement = new Element(FILTER_ELEMENT, namespace);
+ filterElement.setAttribute(NAME_ATTRIBUTE, filter.getName());
+ String value = filter.getValue();
+ if (filter.isBoolean()) {
+ if ("excluded".equalsIgnoreCase(value)) {
+ filterElement.setAttribute("excluded", "1");
+ } else {
+ filterElement.setAttribute("excluded", "0");
+ }
+ } else {
+ if (value == null) {
+ filterElement.setAttribute("value", "");
+ } else {
+ filterElement.setAttribute("value", value);
+ }
+ }
+ if (filter.isList()) {
+ filterElement.setAttribute("list", "true");
+ }
+ return filterElement;
+ }
+
+ /**
+ * Creates a <code>Query</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @param namespace
+ * the <code>Namespace</code> containing the
+ * <code>Element</code>
+ * @return a deserialized <code>Query</code>
+ */
+ public static Query elementToQuery(Element element, Namespace namespace) {
+ String virtualSchema = element.getAttributeValue(SCHEMA_ATTRIBUTE);
+ int count = Integer.parseInt(element.getAttributeValue(COUNT_ATTRIBUTE));
+ String version = element.getAttributeValue(VERSION_ATTRIBUTE);
+ String formatter = element.getAttributeValue(FORMATTER_ATTRIBUTE);
+ String requestId = element.getAttributeValue(REQUEST_ID_ATTRIBUTE);
+ Query query = new Query(virtualSchema, count, version, requestId);
+ query.setFormatter(formatter);
+ String uniqueRows = element.getAttributeValue(UNIQUE_ROWS_ATTRIBUTE);
+ if (uniqueRows != null) {
+ query.setUniqueRows(Integer.parseInt(uniqueRows));
+ }
+ List<Element> datasets = element.getChildren(DATASET_ELEMENT, namespace);
+ for (Element datasetElement : datasets) {
+ query.addDataset(elementToDataset(datasetElement, namespace));
+ }
+ List<Element> links = element.getChildren(LINK_ELEMENT, namespace);
+ for (Element linkElement : links) {
+ query.addLink(elementToLink(linkElement));
+ }
+ return query;
+ }
+
+ /**
+ * Creates a <code>Dataset</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @param namespace
+ * the <code>Namespace</code> containing the
+ * <code>Element</code>
+ * @return a deserialized <code>Dataset</code>
+ */
+ public static Dataset elementToDataset(Element element, Namespace namespace) {
+ Dataset dataset = new Dataset(element.getAttributeValue(NAME_ATTRIBUTE));
+
+ List<Element> attributes = element.getChildren(ATTRIBUTE_ELEMENT, namespace);
+ for (Element attributeElement : attributes) {
+ dataset.addAttribute(elementToAttribute(attributeElement));
+ }
+
+ List<Element> filters = element.getChildren(FILTER_ELEMENT, namespace);
+ for (Element filterElement : filters) {
+ dataset.addFilter(elementToFilter(filterElement));
+ }
+ return dataset;
+ }
+
+ /**
+ * Creates a <code>Filter</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @return a deserialized <code>Filter</code>
+ */
+ public static Filter elementToFilter(Element element) {
+ Filter filter;
+ String filterName = element.getAttributeValue(NAME_ATTRIBUTE);
+ String filterValue = element.getAttributeValue("value");
+ if (filterValue != null) {
+ filter = new Filter(filterName, filterValue);
+ } else {
+ filterValue = element.getAttributeValue("excluded");
+ if ("1".equals(filterValue)) {
+ filter = new Filter(filterName, "excluded", true);
+ } else {
+ filter = new Filter(filterName, "only", true);
+ }
+ }
+ String listValue = element.getAttributeValue("list");
+ if ("true".equals(listValue)) {
+ filter.setList(true);
+ }
+ return filter;
+ }
+
+ /**
+ * Creates an <code>Attribute</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @return a deserialized <code>Attribute</code>
+ */
+ public static Attribute elementToAttribute(Element element) {
+ String attributeName = element.getAttributeValue(NAME_ATTRIBUTE);
+ Attribute attribute = new Attribute(attributeName);
+ String attributes = element.getAttributeValue(ATTRIBUTES_ATTRIBUTE);
+ if (attributes != null) {
+ attribute.setAttributes(attributes);
+ }
+ return attribute;
+ }
+
+ /**
+ * Creates an <code>Link</code> from an XML element.
+ *
+ * @param element
+ * the <code>Element</code> to deserialize
+ * @return a deserialized <code>Link</code>
+ * @deprecated MartJ 0.5 won't require links to be specified
+ */
+ public static Link elementToLink(Element element) {
+ return new Link(element.getAttributeValue("source"), element
+ .getAttributeValue("target"), element
+ .getAttributeValue("defaultLink"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/contract.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/contract.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/contract.gif
new file mode 100644
index 0000000..8325346
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/contract.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/expand.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/expand.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/expand.gif
new file mode 100644
index 0000000..7d3ddff
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/expand.gif differ
http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/a87b4151/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic.gif
----------------------------------------------------------------------
diff --git a/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic.gif b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic.gif
new file mode 100644
index 0000000..bbd2318
Binary files /dev/null and b/taverna-biomart-martservice/src/main/resources/org/biomart/martservice/config/ui/gene_schematic.gif differ