[MOBY-guts] biomoby commit
senger@ebi.ac.uk
senger at pub.open-bio.org
Sun Mar 2 20:48:26 UTC 2003
senger
Sun Mar 2 15:48:26 EST 2003
Update of /home/repository/moby/moby-live/Java/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv25704/org/biomoby/client
Modified Files:
CentralImpl.java
Added Files:
package.html
Log Message:
updated Moby in Java, add new client, add documentation
moby-live/Java/org/biomoby/client package.html,NONE,1.1 CentralImpl.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/org/biomoby/client/CentralImpl.java 2003/02/27 16:28:29 1.1
+++ /home/repository/moby/moby-live/Java/org/biomoby/client/CentralImpl.java 2003/03/02 20:48:26 1.2
@@ -24,27 +24,32 @@
/**
- * A default client to the Moby Registry service implementing
- * interface {@link org.biomoby.registry.Central Central} interface.
+ * A default implementation of the
+ * interface {@link org.biomoby.shared.Central Central}
+ * allowing access to a Moby registry.
*<p>
* This class is supposed to be used by all other clients that wish
* to communicate with the Moby Registry, but do not want to know
- * about XML details necessary for talking with the Moby Central
+ * about all XML details that are necessary for talking with the Moby Central
* directly. This is an example of a client program:
*<pre>
- * import org.biomoby.registry.Central;
- * import org.biomoby.registry.BiomobyException;
+ * import org.biomoby.shared.Central;
+ * import org.biomoby.shared.MobyException;
* import org.biomoby.client.*;
*
* public class Test {
*
* public static void main (String[] args)
- * throws BiomobyException {
+ * throws MobyException {
*
* Central worker = new CentralImpl();
- * String[] names = worker.retrieveServiceNames();
- * for (int i = 0; i < names.length; i++)
- * System.out.println (names[i]);
+ * Map names = worker.getServiceNames();
+ *
+ * for (Iterator it = names.entrySet().iterator(); it.hasNext(); ) {
+ * Map.Entry entry = (Map.Entry)it.next();
+ * System.out.println (entry.getKey());
+ * System.out.println ("\t" + entry.getValue());
+ * }
* }
* }
*</pre>
@@ -61,32 +66,56 @@
private String uri;
private ParserWrapper parser;
+ /** Default location (endpoint) of a Moby registry. */
+ public static final String DEFAULT_ENDPOINT = "http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY-Central.pl";
+ // "http://198.166.4.151/cgi-bin/MOBY-Central.pl";
+
+ /** Default namespace used by the contacted Moby registry. */
+ public static final String DEFAULT_NAMESPACE = "http://mobycentral.cbr.nrc.ca/MOBY/Central";
+
/*************************************************************************
- * Default constructor.
+ * Default constructor. It connects to a default Moby registry
+ * (as defined in {@link #DEFAULT_ENDPOINT}) using a default namespace
+ * (as defined int {@link #DEFAULT_NAMESPACE}).
*************************************************************************/
public CentralImpl()
- throws BiomobyException {
-
- // use default values
- this ("http://mobycentral.cbr.nrc.ca/cgi-bin/MOBY-Central.pl",
- "http://mobycentral.cbr.nrc.ca/MOBY/Central");
+ throws MobyException {
+ this (DEFAULT_ENDPOINT, DEFAULT_NAMESPACE);
}
- // String endpoint = "http://198.166.4.151/cgi-bin/MOBY-Central.pl";
/*************************************************************************
* Constructor allowing to specify which Moby Registry to use.
+ *
+ * @throws MobyException if 'endpoint' is not a valid URL, or if no
+ * DOM parser is available
+ *************************************************************************/
+ public CentralImpl (String endpoint)
+ throws MobyException {
+ this (endpoint, DEFAULT_NAMESPACE);
+ }
+
+ /*************************************************************************
+ * Constructor allowing to specify which Moby Registry and what
+ * namespace to use. If any of the parameters is null, its default
+ * value is used instead.
*<p>
- * @throws BiomobyException if 'endpoint' is not a valid URL, or if no
+ * @throws MobyException if 'endpoint' is not a valid URL, or if no
* DOM parser was found
*************************************************************************/
- public CentralImpl (String endpoint, String uri)
- throws BiomobyException {
+ public CentralImpl (String endpoint, String namespace)
+ throws MobyException {
+
+ if (endpoint == null)
+ endpoint = DEFAULT_ENDPOINT;
+ if (namespace == null)
+ namespace = DEFAULT_NAMESPACE;
+
try {
this.endpoint = new URL (endpoint);
} catch (MalformedURLException e) {
- throw new BiomobyException ("Bad URL: " + endpoint);
+ throw new MobyException ("Bad URL: " + endpoint);
}
- this.uri = uri;
+ this.uri = namespace;
// instantiate a DOM parser
parser = Utils.getDOMParser();
@@ -96,38 +125,201 @@
* Call 'method' with 'parameters' and return its result.
*************************************************************************/
protected Object doCall (String method, Object[] parameters)
- throws BiomobyException {
+ throws MobyException {
Call call = null;
try {
Service service = new Service();
-// AxisEngine engine = service.getEngine();
-// engine.setOption (AxisEngine.PROP_DOMULTIREFS, new Boolean (false));
call = (Call) service.createCall();
call.setTargetEndpointAddress (endpoint);
return call.invoke (uri, method, parameters);
} catch (AxisFault e) {
- throw new BiomobyException (Utils.formatFault (e, endpoint.toString(),
+ throw new MobyException (Utils.formatFault (e, endpoint.toString(),
(call == null ? null : call.getOperationName())));
} catch (Exception e) {
- throw new BiomobyException (e.toString());
+ throw new MobyException (e.toString());
// e.printStackTrace();
}
}
/**************************************************************************
+ * Parse the given XML sniplet to find tag 'success'. If it has value '1'
+ * look further for tag 'id' and return it back (or return an empty string
+ * if ID is not there). Otherwise raise an exception with the 'culprit'
+ * and with the message from the tag 'message'.
+ *
+ * This is how the XML is supposed to look:
+ * <MOBYRegistration>
+ * <id>000057</id>
+ * <success>1</success>
+ * <message><![CDATA[]]></message>
+ * </MOBYRegistration>
+ *
+ *************************************************************************/
+ protected String checkRegistration (String xml, Object culprit)
+ throws MobyException, NoSuccessException {
+
+ String id = "", success = "0", message = "";
+
+ // parse returned XML
+ Document document = parser.parse (new StringReader (xml));
+ Element root = document.getDocumentElement();
+ NodeList children = root.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ if (children.item (i).getNodeType() != Node.ELEMENT_NODE)
+ continue;
+ Element elem = (Element)children.item (i);
+ if (elem.getNodeName().equals ("id")) {
+ if (elem.getFirstChild() != null)
+ id = elem.getFirstChild().getNodeValue();
+ } else if (elem.getNodeName().equals ("success")) {
+ if (elem.getFirstChild() != null)
+ success = elem.getFirstChild().getNodeValue();
+ } else if (elem.getNodeName().equals ("message")) {
+ if (elem.getFirstChild() != null)
+ message = elem.getFirstChild().getNodeValue();
+ }
+ }
+
+ if (success.equals ("0"))
+ throw new NoSuccessException (message, culprit);
+ return id;
+ }
+
+ /**************************************************************************
+ * Return a piece of XML created from the definitions of input data types
+ * of the given service. The returned XML looks like this:
+ *
+ * <Input>
+ * <objectType>objectType1</objectType>
+ * <namespaceType>namespace1</namespaceType>
+ * </Input>
+ * <Input>
+ * <objectType>objectType2</objectType>
+ * <namespaceType>namespace2</namespaceType>
+ * </Input>
+ *
+ *************************************************************************/
+ protected String buildInputTag (MobyService service) {
+ StringBuffer buf = new StringBuffer();
+ synchronized (service) { // because of two arrays: inputs and namespaces
+ String[] inputs = service.getInputTypes();
+ String[] namespaces = service.getInputNamespaces();
+ for (int i = 0; i < inputs.length; i++) {
+ buf.append ("<Input>");
+ buf.append ("<objectType>");
+ buf.append (inputs[i]);
+ buf.append ("</objectType>");
+ buf.append ("<namespaceType>");
+ buf.append (namespaces[i]);
+ buf.append ("</namespaceType>");
+ buf.append ("</Input>");
+ }
+ }
+ return new String (buf);
+ }
+
+ /**************************************************************************
+ * Return a piece of XML created from the definitions of output data types
+ * of the given service. The returned XML looks like this:
+ *
+ * <objectType>objectType1</objectType>
+ * <objectType>objectType2</objectType>
+ *
+ *************************************************************************/
+ protected String buildOutputTag (MobyService service) {
+ StringBuffer buf = new StringBuffer();
+ String[] outputs = service.getOutputTypes();
+ for (int i = 0; i < outputs.length; i++) {
+ buf.append ("<objectType>");
+ buf.append (outputs[i]);
+ buf.append ("</objectType>");
+ }
+ return new String (buf);
+ }
+
+ /**************************************************************************
+ * Extract one or more MobyService objects from the given XML piece.
+ * The XML should look like this:
+ *
+ * <Services>
+ * <Service authURI='org.embl.ebi.senger' serviceName='TestingServiceNew'>
+ * <Category>moby</Category>
+ * <serviceType>TestingServiceType_1046534014379</serviceType>
+ * <outputObject>TestingObjectTypeNew</outputObject>
+ * <Description><![CDATA[Just testing...]]></Description>
+ * </Service>
+ * <Service authURI='org.embl.ebi.senger' serviceName='TestingService_1046534014378'>
+ * <Category>moby</Category>
+ * <serviceType>TestingServiceType_1046534014379</serviceType>
+ * <outputObject>TestingObjectType4_1046534014379</outputObject>
+ * <Description><![CDATA[This is ONLY A TESTING service.]]></Description>
+ * </Service>
+ * </Services>
+ *
+ * Throws an exception if the XML document is invalid.
+ *************************************************************************/
+ protected MobyService[] extractServices (String xml)
+ throws MobyException {
+
+ Document document = parser.parse (new StringReader (xml));
+ NodeList list = document.getElementsByTagName ("Service");
+ MobyService[] results = new MobyService [list.getLength()];
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element)list.item (i);
+ MobyService service = new MobyService (elem.getAttribute ("serviceName"));
+ service.setAuthority (elem.getAttribute ("authURI"));
+ NodeList children = elem.getChildNodes();
+ for (int j = 0; j < children.getLength(); j++) {
+ String nodeName = children.item (j).getNodeName();
+ if (nodeName.equals ("Description")) {
+ service.setDescription (children.item (j).getFirstChild().getNodeValue());
+ } else if (nodeName.equals ("Category") || nodeName.equals ("Catagory")) {
+ service.setCategory (children.item (j).getFirstChild().getNodeValue());
+ } else if (nodeName.equals ("serviceType")) {
+ service.setType (children.item (j).getFirstChild().getNodeValue());
+ } else if (nodeName.equals ("outputObject")) {
+ service.addOutputType (children.item (j).getFirstChild().getNodeValue());
+ }
+ }
+ results [i] = service;
+ }
+ return results;
+ }
+
+ /**************************************************************************
*
*************************************************************************/
- public String[] retrieveServiceNames()
- throws BiomobyException {
+ public Map getServiceNames()
+ throws MobyException {
String result = (String)doCall ("retrieveServiceNames",
new Object[] {});
// parse returned XML
+ Map results = new HashMap();
Document document = parser.parse (new StringReader (result));
NodeList list = document.getElementsByTagName ("serviceName");
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element)list.item (i);
+ results.put (elem.getAttribute ("name"),
+ elem.getAttribute ("authURI"));
+ }
+ return results;
+ }
+
+ /**************************************************************************
+ *
+ *************************************************************************/
+ public String[] getProviders()
+ throws MobyException {
+ String result = (String)doCall ("retrieveServiceProviders",
+ new Object[] {});
+
+ // parse returned XML
+ Document document = parser.parse (new StringReader (result));
+ NodeList list = document.getElementsByTagName ("serviceProvider");
String[] results = new String [list.getLength()];
for (int i = 0; i < list.getLength(); i++)
results[i] = ((Element)list.item (i)).getAttribute ("name");
@@ -137,115 +329,441 @@
/**************************************************************************
*
*************************************************************************/
- public String[] retrieveServiceProviders()
- throws BiomobyException {
- return null;
+ public Map getServiceTypes()
+ throws MobyException {
+ String result = (String)doCall ("retrieveServiceTypes",
+ new Object[] {});
+
+ // parse returned XML
+ Map results = new HashMap();
+ Document document = parser.parse (new StringReader (result));
+ NodeList list = document.getElementsByTagName ("serviceType");
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element)list.item (i);
+ NodeList children = elem.getChildNodes();
+ for (int j = 0; j < children.getLength(); j++) {
+ if (children.item (j).getNodeName().equals ("Description")) {
+ results.put (elem.getAttribute ("name"),
+ children.item (j).getFirstChild().getNodeValue());
+ break;
+ }
+ }
+ }
+ return results;
}
-// /**************************************************************************
-// * Get the list of all registered service types.
-// *<p>
-// * @throws BiomobyException if communication with the Moby Registry fails
-// *************************************************************************/
-// String[] retrieveServiceTypes()
-// throws BiomobyException;
+ /**************************************************************************
+ *
+ *************************************************************************/
+ public Map getNamespaces()
+ throws MobyException {
+ String result = (String)doCall ("retrieveNamespaces",
+ new Object[] {});
-// /**************************************************************************
-// * Get the list of all registered namespaces.
-// *<p>
-// * @throws BiomobyException if communication with the Moby Registry fails
-// *************************************************************************/
-// String[] retrieveNamespaces()
-// throws BiomobyException;
+ // parse returned XML
+ Map results = new HashMap();
+ Document document = parser.parse (new StringReader (result));
+ NodeList list = document.getElementsByTagName ("Namespace");
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element)list.item (i);
+ NodeList children = elem.getChildNodes();
+ for (int j = 0; j < children.getLength(); j++) {
+ if (children.item (j).getNodeName().equals ("Description")) {
+ results.put (elem.getAttribute ("name"),
+ children.item (j).getFirstChild().getNodeValue());
+ break;
+ }
+ }
+ }
+ return results;
+ }
-// /**************************************************************************
-// * Get the list of all registered Object types.
-// *<p>
-// * @throws BiomobyException if communication with the Moby Registry fails
-// *************************************************************************/
-// String[] retrieveObjectNames()
-// throws BiomobyException;
+ /**************************************************************************
+ *
+ *************************************************************************/
+ public Map getDataTypeNames()
+ throws MobyException {
+ String result = (String)doCall ("retrieveObjectNames",
+ new Object[] {});
+ // parse returned XML
+ Map results = new HashMap();
+ Document document = parser.parse (new StringReader (result));
+ NodeList list = document.getElementsByTagName ("Object");
+ for (int i = 0; i < list.getLength(); i++) {
+ Element elem = (Element)list.item (i);
+ NodeList children = elem.getChildNodes();
+ for (int j = 0; j < children.getLength(); j++) {
+ if (children.item (j).getNodeName().equals ("Description")) {
+ results.put (elem.getAttribute ("name"),
+ children.item (j).getFirstChild().getNodeValue());
+ break;
+ }
+ }
+ }
+ return results;
+ }
-// /**************************************************************************
-// * Get the service names/descriptions for a particular type of
-// * Service (and child-types).
-// *************************************************************************/
-// String locateServiceByType (MobyCentral moby,
-// String serviceType,
-// int maxReturn,
-// int expand);
+ /**************************************************************************
+ *
+ *************************************************************************/
+ public String getDataType (String dataTypeName)
+ throws MobyException, NoSuccessException {
+ String result =
+ (String)doCall ("retrieveObject",
+ new Object[] {
+ "<retrieveObject>" +
+ "<objectType>" + dataTypeName + "</objectType>" +
+ "</retrieveObject>"
+ });
+
+ // parse returned XML (hack: taking blindly everything in the Schema tag)
+ String xsd = "";
+ int pos = result.indexOf ("<Schema>");
+ if (pos == 1)
+ throw new NoSuccessException ("Data Type name was not founnd.",
+ dataTypeName);
+ int pos2 = result.indexOf ("</Schema>");
+ if (pos2 < pos)
+ throw new NoSuccessException ("Something wrong with the returned XML.",
+ result);
+ return result.substring (pos + 8, pos2);
+ }
-// /**************************************************************************
-// * Get the names/descriptions for services that use certain INPUT's.
-// *************************************************************************/
-// String locateServiceByInput (MobyCentral moby,
-// String[] inputTypes,
-// String[] namespaces,
-// String serviceType,
-// String providerName,
-// int maxReturn,
-// int fullObjects,
-// int fullServices);
+ /**************************************************************************
+ *
+ *************************************************************************/
+ public String getServiceWSDL (String serviceName)
+ throws MobyException, NoSuccessException {
-// /**************************************************************************
-// * Get the names/descriptions for services that use certain OUTPUT.
-// *************************************************************************/
-// String locateServiceByoutput (MobyCentral moby,
-// String outputType,
-// String[] namespaces,
-// String serviceType,
-// String providerName,
-// int maxReturn,
-// int fullObjects,
-// int fullServices);
+ Map names = getServiceNames();
-// /**************************************************************************
-// * Get the WSDL descriptions for services with this service name.
-// *************************************************************************/
-// String retrieveService (MobyCentral moby,
-// String providerName,
-// String serviceName);
+ for (Iterator it = names.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry)it.next();
+ if ( ((String)entry.getKey()).equals (serviceName) )
+ return getServiceWSDL (serviceName, (String)entry.getValue());
+ }
-// /**************************************************************************
-// * Get the object xsd.
-// *************************************************************************/
-// String retrieveObject (MobyCentral moby,
-// String objectName);
+ throw new NoSuccessException ("Service not found.", serviceName);
+ }
/**************************************************************************
- * Register a new Object type, and its relationships, or modify existing.
+ *
*************************************************************************/
- /* ... registerObject (MobyCentral moby, ...) */
+ public String getServiceWSDL (String serviceName, String authority)
+ throws MobyException, NoSuccessException {
+ String result =
+ (String)doCall ("retrieveService",
+ new Object[] {
+ "<retrieveService>" +
+ "<authURI>" + authority + "</authURI>" +
+ "<serviceName>" + serviceName + "</serviceName>" +
+ "</retrieveService>"
+ });
- /**************************************************************************
- * De-register an Object type, and its relationships.
+ // parse returned XML
+ Document document = parser.parse (new StringReader (result));
+ Element service = document.getDocumentElement();
+ Node wsdl = service.getFirstChild();
+ if (wsdl == null)
+ throw new NoSuccessException ("Service not found.",
+ serviceName + " (" + authority + ")");
+ return wsdl.getNodeValue();
+ }
+
+ /*************************************************************************
+ *
*************************************************************************/
- /* ... deregisterObject (MobyCentral moby, ...) */
+ public void registerDataType (MobyDataType dataType)
+ throws MobyException, NoSuccessException {
- /**************************************************************************
- * Register a new Service type, and its relationships.
+ // build the ISA tag (expressing hierarchy of data types)
+ String[] names = dataType.getParentNames();
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < names.length; i++) {
+ buf.append ("<objectType>");
+ buf.append (names[i]);
+ buf.append ("</objectType>");
+ buf.append ("\n");
+ }
+
+ String result =
+ (String)doCall ("registerObject",
+ new Object[] {
+ "<registerObject>" +
+ "<objectType>" + dataType.getName() + "</objectType>" +
+ "<Description><![CDATA[" + dataType.getDescription() + "]]>" +
+ "</Description>" +
+ "<ISA>" + new String (buf) + "</ISA>" +
+ "<authURI>" + dataType.getAuthority() + "</authURI>" +
+ "<Clobber>2</Clobber>" +
+ "<xsd>" + dataType.getXSD() + "</xsd>" +
+ "</registerObject>"
+ });
+ dataType.setId (checkRegistration (result, dataType));
+ }
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void unregisterDataType (MobyDataType dataType)
+ throws MobyException, NoSuccessException {
+ if (dataType.getId() == null)
+ throw new NoSuccessException ("Can't unregister a data type - unknown ID.", dataType);
+ String result =
+ (String)doCall ("deregisterObject",
+ new Object[] {
+ "<deregisterObject>" +
+ "<objectAcc>" + dataType.getId() + "</objectAcc>" +
+ "</deregisterObject>"
+ });
+ checkRegistration (result, dataType);
+ }
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void registerServiceType (MobyServiceType serviceType)
+ throws MobyException, NoSuccessException {
+
+ // build the ISA tag (expressing hierarchy of service types)
+ String[] names = serviceType.getParentNames();
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < names.length; i++) {
+ buf.append ("<serviceType>");
+ buf.append (names[i]);
+ buf.append ("</serviceType>");
+ buf.append ("\n");
+ }
+
+ String result =
+ (String)doCall ("registerServiceType",
+ new Object[] {
+ "<registerServiceType>" +
+ "<serviceType>" + serviceType.getName() + "</serviceType>" +
+ "<Description><![CDATA[" + serviceType.getDescription() + "]]>" +
+ "</Description>" +
+ "<ISA>" + new String (buf) + "</ISA>" +
+ "</registerServiceType>"
+ });
+ serviceType.setId (checkRegistration (result, serviceType));
+ }
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void unregisterServiceType (MobyServiceType serviceType)
+ throws MobyException, NoSuccessException {
+ if (serviceType.getId() == null)
+ throw new NoSuccessException ("Can't unregister a service type - unknown ID.", serviceType);
+ String result =
+ (String)doCall ("deregisterServiceType",
+ new Object[] {
+ "<deregisterServiceType>" +
+ "<serviceTypeAcc>" + serviceType.getId() + "</serviceTypeAcc>" +
+ "</deregisterServiceType>"
+ });
+ checkRegistration (result, serviceType);
+ }
+
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void registerNamespace (MobyNamespace namespace)
+ throws MobyException, NoSuccessException {
+ String result =
+ (String)doCall ("registerNamespace",
+ new Object[] {
+ "<registerNamespace>" +
+ "<namespaceType>" + namespace.getName() + "</namespaceType>" +
+ "<authURI>" + namespace.getAuthority() + "</authURI>" +
+ "<Description><![CDATA[" + namespace.getDescription() + "]]>" +
+ "</Description>" +
+ "<Clobber>2</Clobber>" +
+ "</registerNamespace>"
+ });
+ namespace.setId (checkRegistration (result, namespace));
+ }
+
+ /*************************************************************************
+ *
*************************************************************************/
- /* ... registerServiceType (MobyCentral moby, ...) */
+ public void unregisterNamespace (MobyNamespace namespace)
+ throws MobyException, NoSuccessException {
+ if (namespace.getId() == null)
+ throw new NoSuccessException ("Can't unregister a namespace - unknown ID.", namespace);
+ String result =
+ (String)doCall ("deregisterNamespace",
+ new Object[] {
+ "<deregisterNamespace>" +
+ "<namespaceAcc>" + namespace.getId() + "</namespaceAcc>" +
+ "</deregisterNamespace>"
+ });
+ checkRegistration (result, namespace);
+ }
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void registerService (MobyService service)
+ throws MobyException, NoSuccessException {
+
+ String result =
+ (String)doCall ("registerService",
+ new Object[] {
+ "<registerService>" +
+ "<Category>" + service.getCategory() + "</Category>" +
+ "<serviceName>" + service.getName() + "</serviceName>" +
+ "<serviceType>" + service.getType() + "</serviceType>" +
+ "<authURI>" + service.getAuthority() + "</authURI>" +
+ "<inputObjects>" + buildInputTag (service) + "</inputObjects>" +
+ "<outputObjects>" + buildOutputTag (service) + "</outputObjects>" +
+ "<URL>" + service.getURL() + "</URL>" +
+ "<Description><![CDATA[" + service.getDescription() + "]]>" +
+ "</Description>" +
+ "</registerService>"
+ });
+ service.setId (checkRegistration (result, service));
+ }
+
+ /*************************************************************************
+ *
+ *************************************************************************/
+ public void unregisterService (MobyService service)
+ throws MobyException, NoSuccessException {
+ if (service.getId() == null)
+ throw new NoSuccessException ("Can't unregister a service - unknown ID.", service);
+ String result =
+ (String)doCall ("deregisterService",
+ new Object[] {
+ "<deregisterService>" +
+ "<serviceID>" + service.getId() + "</serviceID>" +
+ "</deregisterService>"
+ });
+ checkRegistration (result, service);
+ }
/**************************************************************************
- * Register a new Namespace.
+ *
*************************************************************************/
- /* ... registerNamespace (MobyCentral moby, ...) */
+ public MobyService[] findService (String serviceType)
+ throws MobyException {
+ String result =
+ (String)doCall ("locateServiceByType",
+ new Object[] {
+ "<locateServiceByType>" +
+ "<serviceType>" + serviceType + "</serviceType>" +
+ "<fullServices>1</fullServices>" +
+ "</locateServiceByType>"
+ });
+ return extractServices (result);
+ }
/**************************************************************************
- * Register a new MOBY Service.
+ *
*************************************************************************/
- /* ... registerService (MobyCentral moby, ...) */
+ public MobyService[] findService (String[] keywords)
+ throws MobyException {
+ if (keywords == null)
+ return new MobyService[] {};
+
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < keywords.length; i++) {
+ buf.append ("<keyword>");
+ buf.append (keywords[i]);
+ buf.append ("</keyword>");
+ }
+
+ String result =
+ (String)doCall ("locateServiceByKeywords",
+ new Object[] {
+ "<locateServiceByKeywords>" +
+ new String (buf) +
+ "<fullServices>1</fullServices>" +
+ "</locateServiceByKeywords>"
+ });
+ return extractServices (result);
+ }
/**************************************************************************
- * Register a new Service type, and its relationships, via WSDL.
+ *
*************************************************************************/
- /* ... registerServiceWSDL (MobyCentral moby, ...) */
+ public MobyService[] findService (MobyService pattern)
+ throws MobyException {
+ if (pattern == null)
+ return new MobyService[] {};
+ int iLen = pattern.getInputTypes().length;
+ int oLen = pattern.getOutputTypes().length;
+ if (iLen == 0 && oLen == 0)
+ return new MobyService[] {};
+
+ MobyService[] byInput = null;
+ MobyService[] byOutput = null;
+
+ // locate service by input types
+ if (iLen > 0) {
+ String result =
+ (String)doCall ("locateServiceByInput",
+ new Object[] {
+ "<locateServiceByInput>" +
+ "<inputObjects>" + buildInputTag (pattern) + "</inputObjects>" +
+ "<serviceType>" + pattern.getType() + "</serviceType>" +
+ "<authURI>" + pattern.getAuthority() + "</authURI>" +
+ "<fullObjects>1</fullObjects>" +
+ "<fullServices>1</fullServices>" +
+ "</locateServiceByInput>"
+ });
+ byInput = extractServices (result);
+ if (oLen == 0)
+ return byInput;
+ }
+
+ // locate service by output types
+ if (oLen > 0) {
+ String result =
+ (String)doCall ("locateServiceByOutput",
+ new Object[] {
+ "<locateServiceByOutput>" +
+ buildOutputTag (pattern) +
+ "<serviceType>" + pattern.getType() + "</serviceType>" +
+ "<authURI>" + pattern.getAuthority() + "</authURI>" +
+ "<fullObjects>1</fullObjects>" +
+ "<fullServices>1</fullServices>" +
+ "</locateServiceByOutput>"
+ });
+ byOutput = extractServices (result);
+ if (iLen == 0)
+ return byOutput;
+ }
+
+ // if we are still here, build an intersection
+ if (byInput == null || byOutput == null)
+ return new MobyService[] {};
+ Vector v = new Vector();
+ for (int i = 0; i < byInput.length; i++) {
+ for (int j = 0; j < byOutput.length; j++) {
+ if (byInput[i].equals (byOutput[j])) {
+ v.addElement (byInput[i]);
+ break;
+ }
+ }
+ }
+ MobyService[] results = new MobyService [v.size()];
+ v.copyInto (results);
+ return results;
+ }
/**************************************************************************
- * Deregister a Service.
+ *
*************************************************************************/
- /* ... deregisterService (MobyCentral moby, ...) */
+ public String call (String methodName, String inputXML)
+ throws MobyException {
+ if (inputXML == null || inputXML.equals (""))
+ return (String)doCall (methodName, new Object[] { });
+ else
+ return (String)doCall (methodName, new Object[] { inputXML });
+ }
+
}
More information about the MOBY-guts
mailing list