http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java deleted file mode 100644 index c33a5bf..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivity.java +++ /dev/null @@ -1,417 +0,0 @@ -/******************************************************************************* - * 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/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java deleted file mode 100644 index 1f02e7e..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityConfigurationBean.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * 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/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java deleted file mode 100644 index 8da531e..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * 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/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java deleted file mode 100644 index 0ca0d38..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/MobyParseDatatypeActivityHealthChecker.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * 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/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java deleted file mode 100644 index 042b6e8..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/ParseMobyXML.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-taverna-plugin-bioinformatics/blob/709e8c1c/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java ---------------------------------------------------------------------- diff --git a/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java b/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java deleted file mode 100644 index a7b873c..0000000 --- a/src/main/java/net/sf/taverna/t2/activities/biomoby/RetrieveWsdlThread.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * 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) { - - } - } -}