[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Wed Mar 15 20:23:47 UTC 2006


kawas
Wed Mar 15 15:23:47 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended
In directory pub.open-bio.org:/tmp/cvs-serv718/org/biomoby/shared/extended

Modified Files:
	ServiceInstanceParser.java 
Log Message:
stripped lsids from inputs/outputs and namespaces so that these parsed services can be registered into mobycentral.

moby-live/Java/src/main/org/biomoby/shared/extended ServiceInstanceParser.java,1.11,1.12
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java	2006/03/15 17:28:15	1.11
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java	2006/03/15 20:23:47	1.12
@@ -33,6 +33,8 @@
 import com.hp.hpl.jena.shared.JenaException;
 import com.hp.hpl.jena.vocabulary.DC;
 import com.hp.hpl.jena.vocabulary.RDF;
+import com.ibm.lsid.LSID;
+import com.ibm.lsid.MalformedLSIDException;
 
 /**
  * 
@@ -42,25 +44,25 @@
  *         An example of how to use this class is below:
  * 
  * <pre><code>
- *            import org.biomoby.shared.MobyService;
- *            import org.biomoby.shared.Utils;
- *            import org.biomoby.shared.extended.ServiceInstanceParser;
- *            
- *            ...
- *                  
- *                       ServiceInstanceParser p = new ServiceInstanceParser(
- *      				&quot;http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances&quot;);
- *      		MobyService[] services = p.getMobyServicesFromRDF();
- *      		if (!p.isRDFValid()) {
- *      			System.out.println(&quot;One or more services in the RDF were invalid&quot;);
- *      			System.out.println(&quot;The errors are the following:&quot;);
- *      			System.out.println(Utils.format(p.getErrors(),2));
- *      			
+ *             import org.biomoby.shared.MobyService;
+ *             import org.biomoby.shared.Utils;
+ *             import org.biomoby.shared.extended.ServiceInstanceParser;
+ *             
+ *             ...
+ *                   
+ *                        ServiceInstanceParser p = new ServiceInstanceParser(
+ *       				&quot;http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances&quot;);
+ *       		MobyService[] services = p.getMobyServicesFromRDF();
+ *       		if (!p.isRDFValid()) {
+ *       			System.out.println(&quot;One or more services in the RDF were invalid&quot;);
+ *       			System.out.println(&quot;The errors are the following:&quot;);
+ *       			System.out.println(Utils.format(p.getErrors(),2));
+ *       			
+ *        		}
+ *       		System.out.println(&quot;The valid services are:&quot;);
+ *       		for (int i = 0; i &lt; services.length; i++) {
+ *       			System.out.println((services[i]));
  *       		}
- *      		System.out.println(&quot;The valid services are:&quot;);
- *      		for (int i = 0; i &lt; services.length; i++) {
- *      			System.out.println((services[i]));
- *      		}
  * </code></pre>
  * 
  * <p>
@@ -126,8 +128,7 @@
 			this.url = url;
 		else {
 			this.url = null;
-			throw new MobyException("Invalid url specified by "
-					+ url.toExternalForm() + ".");
+			throw new MobyException("Invalid url specified by " + url.toExternalForm() + ".");
 		}
 		this.parsedOkay = false;
 		errors = new StringBuffer();
@@ -173,8 +174,7 @@
 	 * @throws MobyException
 	 *             if there is a parsing error
 	 */
-	public MobyService[] getMobyServicesFromRDF(Model model)
-			throws MobyException {
+	public MobyService[] getMobyServicesFromRDF(Model model) throws MobyException {
 		// clear out any old information
 		ArrayList list = new ArrayList();
 		if (model != null) {
@@ -196,40 +196,34 @@
 		this.errors = new StringBuffer();
 
 		boolean success = true;
-		ResIterator rIterator = model
-				.listSubjectsWithProperty(FetaVocabulary.hasServiceNameText);
+		ResIterator rIterator = model.listSubjectsWithProperty(FetaVocabulary.hasServiceNameText);
 		while (rIterator.hasNext()) {
 			boolean currentlyBad = false;
 			Resource resource = rIterator.nextResource();
 			String name = "";
 			if (resource.hasProperty(FetaVocabulary.hasServiceNameText))
-				name = resource.getProperty(FetaVocabulary.hasServiceNameText)
-						.getObject().toString();
+				name = resource.getProperty(FetaVocabulary.hasServiceNameText).getObject()
+						.toString();
 			MobyService service = new MobyService(name);
 			// set the lsid
 			service.setLSID(resource.getURI());
 			// get the signatureURL
 			String signatureURL = "";
-			if (resource
-					.hasProperty(FetaVocabulary.hasServiceDescriptionLocation))
-				signatureURL = resource.getProperty(
-						FetaVocabulary.hasServiceDescriptionLocation)
+			if (resource.hasProperty(FetaVocabulary.hasServiceDescriptionLocation))
+				signatureURL = resource.getProperty(FetaVocabulary.hasServiceDescriptionLocation)
 						.getObject().toString();
 			service.setSignatureURL(signatureURL);
 			// set the service type
 			if (resource.hasProperty(FetaVocabulary.hasOperation)) {
-				Resource hoResource = resource.getProperty(
-						FetaVocabulary.hasOperation).getResource();
+				Resource hoResource = resource.getProperty(FetaVocabulary.hasOperation)
+						.getResource();
 				if (hoResource.hasProperty(FetaVocabulary.performsTask)) {
-					Resource ptResource = hoResource.getProperty(
-							FetaVocabulary.performsTask).getResource();
-					StmtIterator stmtIterator = ptResource
-							.listProperties(RDF.type);
+					Resource ptResource = hoResource.getProperty(FetaVocabulary.performsTask)
+							.getResource();
+					StmtIterator stmtIterator = ptResource.listProperties(RDF.type);
 					while (stmtIterator.hasNext()) {
-						RDFNode typeNode = stmtIterator.nextStatement()
-								.getObject();
-						if (!typeNode.toString().equals(
-								FetaVocabulary.operationTask.toString())) {
+						RDFNode typeNode = stmtIterator.nextStatement().getObject();
+						if (!typeNode.toString().equals(FetaVocabulary.operationTask.toString())) {
 							String serviceType = typeNode.toString();
 							String[] parsedServiceType = serviceType.split("#");
 							if (parsedServiceType.length == 2)
@@ -244,29 +238,26 @@
 
 			// set the category
 			if (resource.hasProperty(DC.format)) {
-				String category = resource.getProperty(DC.format).getObject()
-						.toString();
+				String category = resource.getProperty(DC.format).getObject().toString();
 				service.setCategory(category);
 			}
 
 			// set the authority, email address and authoritative values
 			if (resource.hasProperty(FetaVocabulary.providedBy)) {
-				Resource org = (Resource) resource.getProperty(
-						FetaVocabulary.providedBy).getObject();
+				Resource org = (Resource) resource.getProperty(FetaVocabulary.providedBy)
+						.getObject();
 				if (org.hasProperty(DC.publisher)) {
-					String authorityURI = org.getProperty(DC.publisher)
-							.getObject().toString();
+					String authorityURI = org.getProperty(DC.publisher).getObject().toString();
 					service.setAuthority(authorityURI);
 				}
 				if (org.hasProperty(DC.creator)) {
-					String email = org.getProperty(DC.creator).getObject()
-							.toString();
+					String email = org.getProperty(DC.creator).getObject().toString();
 					service.setEmailContact(email);
 				}
 				if (org.hasProperty(ServiceDescriptionPredicates.authoritative)) {
 					String authoritative = org.getProperty(
-							ServiceDescriptionPredicates.authoritative)
-							.getObject().toString().trim();
+							ServiceDescriptionPredicates.authoritative).getObject().toString()
+							.trim();
 					if (authoritative.equalsIgnoreCase("true"))
 						service.setAuthoritative(true);
 					else
@@ -276,222 +267,205 @@
 
 			// set the url for the service
 			if (resource.hasProperty(FetaVocabulary.locationURI)) {
-				String serviceUrl = resource.getProperty(
-						FetaVocabulary.locationURI).getObject().toString();
+				String serviceUrl = resource.getProperty(FetaVocabulary.locationURI).getObject()
+						.toString();
 				service.setURL(serviceUrl);
 			}
 			// set the description
 			if (resource.hasProperty(FetaVocabulary.hasServiceDescriptionText)) {
-				String description = resource.getProperty(
-						FetaVocabulary.hasServiceDescriptionText).getObject()
-						.toString();
+				String description = resource.getProperty(FetaVocabulary.hasServiceDescriptionText)
+						.getObject().toString();
 				service.setDescription(description);
 			}
 
 			// process in/outputs
-			StmtIterator arguements = resource
-					.listProperties(FetaVocabulary.hasOperation);
+			StmtIterator arguements = resource.listProperties(FetaVocabulary.hasOperation);
 			while (arguements.hasNext()) {
 				Statement s = arguements.nextStatement();
 				Resource r = (Resource) s.getObject();
-				StmtIterator inputs = r
-						.listProperties(FetaVocabulary.inputParameter);
+				StmtIterator inputs = r.listProperties(FetaVocabulary.inputParameter);
 				// collections to be added at the end the current scope
 				Map inputCollectionMap = new HashMap();
 				Map outputCollectionMap = new HashMap();
 				// is the current service bad?
 				while (inputs.hasNext()) {
 
-					Resource parameter = (Resource) inputs.nextStatement()
-							.getObject();
-					if (!parameter.getProperty(FetaVocabulary.hasParameterType)
-							.getResource().hasProperty(RDF.type)) {
+					Resource parameter = (Resource) inputs.nextStatement().getObject();
+					if (!parameter.getProperty(FetaVocabulary.hasParameterType).getResource()
+							.hasProperty(RDF.type)) {
 						success = false;
 						currentlyBad = true;
-						errors.append(service.getName() + ","
-								+ service.getAuthority()
-								+ "{Input for service "
-								+ service.getName()
+						errors.append(service.getName() + "," + service.getAuthority()
+								+ "{Input for service " + service.getName()
 								+ " did not have a parameter type of type RDF:type}");
 						errors.append(newline);
 						continue;
 					} else {
-						if (parameter.getProperty(
-								FetaVocabulary.hasParameterType).getResource()
-								.getProperty(RDF.type).getObject().toString()
-								.endsWith("simpleParameter")) {
+						if (parameter.getProperty(FetaVocabulary.hasParameterType).getResource()
+								.getProperty(RDF.type).getObject().toString().endsWith(
+										"simpleParameter")) {
 							// we have a simple
 							// make sure that object type and article name exist
-							if (!parameter
-									.hasProperty(ServiceDescriptionPredicates.object_type)) {
+							if (!parameter.hasProperty(ServiceDescriptionPredicates.object_type)) {
 								success = false;
 								currentlyBad = true;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Input for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Input for service " + service.getName()
 										+ " was missing an object type}");
 								errors.append(newline);
 								continue;
 							}
-							if (!parameter
-									.hasProperty(FetaVocabulary.hasParameterNameText)) {
+							if (!parameter.hasProperty(FetaVocabulary.hasParameterNameText)) {
 								currentlyBad = true;
 								success = false;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Input for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Input for service " + service.getName()
 										+ " was missing an article name}");
 								errors.append(newline);
 								continue;
 							}
 
-							// name
-							String datatype = parameter.getProperty(
-									ServiceDescriptionPredicates.object_type)
-									.getObject().toString();
-							if (datatype.indexOf("#") > 0)
-								datatype = datatype.substring(datatype
-										.lastIndexOf("#") + 1);
-							// if (datatype.indexOf(":") > 0)
-							// datatype = datatype.substring(datatype
-							// .lastIndexOf(":") + 1);
+							LSID lsid = null;
+							try {
+								lsid = new LSID(parameter.getProperty(
+										ServiceDescriptionPredicates.object_type).getObject()
+										.toString());
+							} catch (MalformedLSIDException e) {
+								errors
+										.append("There was a problem extracting the input simple parameters' LSID "
+												+ e.getLocalizedMessage());
+								currentlyBad = true;
+								success = false;
+								continue;
+							}
+
+							String datatype = lsid.getObject();
 
 							// extract the article name
 							String articlename = parameter.getProperty(
-									FetaVocabulary.hasParameterNameText)
-									.getObject().toString();
+									FetaVocabulary.hasParameterNameText).getObject().toString();
 							if (articlename.equals("")) {
 								success = false;
 								currentlyBad = true;
-								errors
-										.append(service.getName()
-												+ ","
-												+ service.getAuthority()
-												+ "{Input for service "
-												+ service.getName()
-												+ " was missing a non empty article name}");
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Input for service " + service.getName()
+										+ " was missing a non empty article name}");
 								errors.append(newline);
 								continue;
 							}
 							// check for namespaces
 							ArrayList namespaces = new ArrayList();
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
-								Resource namespaceResource = (Resource) parameter
-										.getProperty(
-												ServiceDescriptionPredicates.inNamespaces)
-										.getObject();
+							if (parameter.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
+								Resource namespaceResource = (Resource) parameter.getProperty(
+										ServiceDescriptionPredicates.inNamespaces).getObject();
 								StmtIterator namespaceIterator = namespaceResource
 										.listProperties(ServiceDescriptionPredicates.namespace_type);
 								while (namespaceIterator.hasNext()) {
-									String namespace = namespaceIterator
-											.nextStatement().getObject()
-											.toString();
-									if (namespace.indexOf("#") > 0)
-										namespace = namespace
-												.substring(namespace
-														.lastIndexOf("#") + 1);
-									// if (namespace.indexOf(":") > 0)
-									// namespace = namespace.substring(namespace
-									// .lastIndexOf(":") + 1);
+
+									LSID nsLSID = null;
+									try {
+										nsLSID = new LSID(namespaceIterator.nextStatement()
+												.getObject().toString());
+									} catch (MalformedLSIDException e) {
+										errors
+												.append("There was a problem extracting the input parameters' namespace LSID "
+														+ e.getLocalizedMessage());
+										currentlyBad = true;
+										success = false;
+										continue;
+									}
+
+									String namespace = nsLSID.getObject();
 									namespaces.add(namespace);
 								}
 							}
 							MobyPrimaryDataSimple primaryInput = new MobyPrimaryDataSimple();
-							primaryInput
-									.setDataType(new MobyDataType(datatype));
+							primaryInput.setDataType(new MobyDataType(datatype));
 							primaryInput.setName(articlename);
 							if (!namespaces.isEmpty()) {
-								for (Iterator nsIterator = namespaces
-										.iterator(); nsIterator.hasNext();) {
-									primaryInput
-											.addNamespace(new MobyNamespace(
-													(String) nsIterator.next()));
+								for (Iterator nsIterator = namespaces.iterator(); nsIterator
+										.hasNext();) {
+									primaryInput.addNamespace(new MobyNamespace((String) nsIterator
+											.next()));
 								}
 							}
 							service.addInput(primaryInput);
-						} else if (parameter.getProperty(
-								FetaVocabulary.hasParameterType).getResource()
-								.getProperty(RDF.type).getObject().toString()
+						} else if (parameter.getProperty(FetaVocabulary.hasParameterType)
+								.getResource().getProperty(RDF.type).getObject().toString()
 								.endsWith("collectionParameter")) {
 							// we have a collection
 							// make sure that object type and article name exist
-							if (!parameter
-									.hasProperty(ServiceDescriptionPredicates.object_type)) {
+							if (!parameter.hasProperty(ServiceDescriptionPredicates.object_type)) {
 								currentlyBad = true;
 								success = false;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Collection input for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection input for service " + service.getName()
 										+ " was missing an object type.}");
 								errors.append(newline);
 								continue;
 							}
-							if (!parameter
-									.hasProperty(FetaVocabulary.hasParameterNameText)) {
+							if (!parameter.hasProperty(FetaVocabulary.hasParameterNameText)) {
 								success = false;
 								currentlyBad = true;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Collection for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection for service " + service.getName()
 										+ " was missing an article name.}");
 								errors.append(newline);
 								continue;
 							}
 							// name
-							String datatype = parameter.getProperty(
-									ServiceDescriptionPredicates.object_type)
-									.getObject().toString();
-							if (datatype.indexOf("#") > 0)
-								datatype = datatype.substring(datatype
-										.lastIndexOf("#") + 1);
-							// if (datatype.indexOf(":") > 0)
-							// datatype = datatype.substring(datatype
-							// .lastIndexOf(":") + 1);
+
+							LSID lsid = null;
+							try {
+								lsid = new LSID(parameter.getProperty(
+										ServiceDescriptionPredicates.object_type).getObject()
+										.toString());
+							} catch (MalformedLSIDException e) {
+								errors
+										.append("There was a problem extracting the collection input parameters' LSID "
+												+ e.getLocalizedMessage());
+								currentlyBad = true;
+								success = false;
+								continue;
+							}
+							String datatype = lsid.getObject();
 
 							// extract the article name
 							String articlename = parameter.getProperty(
-									FetaVocabulary.hasParameterNameText)
-									.getObject().toString();
+									FetaVocabulary.hasParameterNameText).getObject().toString();
 							if (articlename.equals("")) {
 								success = false;
 								currentlyBad = true;
-								errors
-										.append(service.getName()
-												+ ","
-												+ service.getAuthority()
-												+ "{Collection input for service "
-												+ service.getName()
-												+ " was missing a non empty article name.}");
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection input for service " + service.getName()
+										+ " was missing a non empty article name.}");
 								errors.append(newline);
 								continue;
 							}
 
 							// check for namespaces
 							ArrayList namespaces = new ArrayList();
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
-								Resource namespaceResource = (Resource) parameter
-										.getProperty(
-												ServiceDescriptionPredicates.inNamespaces)
-										.getObject();
+							if (parameter.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
+								Resource namespaceResource = (Resource) parameter.getProperty(
+										ServiceDescriptionPredicates.inNamespaces).getObject();
 								StmtIterator namespaceIterator = namespaceResource
 										.listProperties(ServiceDescriptionPredicates.namespace_type);
 								while (namespaceIterator.hasNext()) {
-									String namespace = namespaceIterator
-											.nextStatement().getObject()
-											.toString();
-									if (namespace.indexOf("#") > 0)
-										namespace = namespace
-												.substring(namespace
-														.lastIndexOf("#") + 1);
-									// if (namespace.indexOf(":") > 0)
-									// namespace = namespace.substring(namespace
-									// .lastIndexOf(":") + 1);
+
+									LSID nsLSID = null;
+									try {
+										nsLSID = new LSID(namespaceIterator.nextStatement()
+												.getObject().toString());
+									} catch (MalformedLSIDException e) {
+										errors
+												.append("There was a problem extracting the parameters' LSID "
+														+ e.getLocalizedMessage());
+										currentlyBad = true;
+										success = false;
+										continue;
+									}
+
+									String namespace = nsLSID.getObject();
 									namespaces.add(namespace);
 								}
 							}
@@ -502,38 +476,32 @@
 										.get(articlename);
 							} else
 								collection = new MobyPrimaryDataSet(articlename);
-							MobyPrimaryDataSimple input = new MobyPrimaryDataSimple(
-									"");
+							MobyPrimaryDataSimple input = new MobyPrimaryDataSimple("");
 							input.setDataType(new MobyDataType(datatype));
 							if (!namespaces.isEmpty()) {
-								for (Iterator nsIterator = namespaces
-										.iterator(); nsIterator.hasNext();) {
-									input.addNamespace(new MobyNamespace(
-											(String) nsIterator.next()));
+								for (Iterator nsIterator = namespaces.iterator(); nsIterator
+										.hasNext();) {
+									input
+											.addNamespace(new MobyNamespace((String) nsIterator
+													.next()));
 								}
 							}
 							collection.addElement(input);
 							inputCollectionMap.put(articlename, collection);
-						} else if (parameter.getProperty(
-								FetaVocabulary.hasParameterType).getResource()
-								.getProperty(RDF.type).getObject().toString()
+						} else if (parameter.getProperty(FetaVocabulary.hasParameterType)
+								.getResource().getProperty(RDF.type).getObject().toString()
 								.endsWith("secondaryParameter")) {
 							// we have a secondary
-							if (!parameter
-									.hasProperty(ServiceDescriptionPredicates.datatype)) {
+							if (!parameter.hasProperty(ServiceDescriptionPredicates.datatype)) {
 								currentlyBad = true;
 								success = false;
-								errors
-										.append(service.getName()
-												+ ","
-												+ service.getAuthority()
-												+ "{Invalid secondary input found. Missing moby datatype"
-												+ " (one of String, Float, Integer, DateTime).}");
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Invalid secondary input found. Missing moby datatype"
+										+ " (one of String, Float, Integer, DateTime).}");
 								errors.append(newline);
 								continue;
 							}
-							if (!parameter
-									.hasProperty(FetaVocabulary.hasParameterNameText)) {
+							if (!parameter.hasProperty(FetaVocabulary.hasParameterNameText)) {
 								success = false;
 								currentlyBad = true;
 								errors
@@ -545,18 +513,16 @@
 								continue;
 							}
 							String datatype = parameter.getProperty(
-									ServiceDescriptionPredicates.datatype)
-									.getLiteral().getValue().toString();
+									ServiceDescriptionPredicates.datatype).getLiteral().getValue()
+									.toString();
 							if (datatype.indexOf("#") > 0)
-								datatype = datatype.substring(datatype
-										.indexOf("#") + 1);
+								datatype = datatype.substring(datatype.indexOf("#") + 1);
 							if (datatype.indexOf(":") > 0)
-								datatype = datatype.substring(datatype
-										.indexOf(":") + 1);
+								datatype = datatype.substring(datatype.indexOf(":") + 1);
 							// extract the article name
 							String articlename = parameter.getProperty(
-									FetaVocabulary.hasParameterNameText)
-									.getLiteral().getValue().toString();
+									FetaVocabulary.hasParameterNameText).getLiteral().getValue()
+									.toString();
 							if (articlename.equals("")) {
 								success = false;
 								currentlyBad = true;
@@ -570,82 +536,56 @@
 							}
 
 							// create the datatype
-							MobySecondaryData secondary = new MobySecondaryData(
-									articlename);
+							MobySecondaryData secondary = new MobySecondaryData(articlename);
 							secondary.setDataType(datatype);
 
-							if (parameter
-									.hasProperty(FetaVocabulary.hasDefaultValue)) {
-								secondary.setDefaultValue(parameter
-										.getProperty(
-												FetaVocabulary.hasDefaultValue)
-										.getLiteral().getValue().toString());
+							if (parameter.hasProperty(FetaVocabulary.hasDefaultValue)) {
+								secondary.setDefaultValue(parameter.getProperty(
+										FetaVocabulary.hasDefaultValue).getLiteral().getValue()
+										.toString());
 							}
 							// process the description
 							if (parameter
 									.hasProperty(ServiceDescriptionPredicates.secondary_description)) {
-								secondary
-										.setDescription(parameter
-												.getProperty(
-														ServiceDescriptionPredicates.secondary_description)
-												.getLiteral().getValue()
-												.toString());
+								secondary.setDescription(parameter.getProperty(
+										ServiceDescriptionPredicates.secondary_description)
+										.getLiteral().getValue().toString());
 							}
 
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.max)) {
+							if (parameter.hasProperty(ServiceDescriptionPredicates.max)) {
 								try {
-									secondary
-											.setMaximumValue(Integer
-													.parseInt(parameter
-															.getProperty(
-																	ServiceDescriptionPredicates.max)
-															.getLiteral()
-															.getValue()
-															.toString()));
+									secondary.setMaximumValue(Integer.parseInt(parameter
+											.getProperty(ServiceDescriptionPredicates.max)
+											.getLiteral().getValue().toString()));
 								} catch (NumberFormatException e) {
 									success = false;
 									currentlyBad = true;
-									errors
-											.append(service.getName()
-													+ ","
-													+ service.getAuthority()
-													+ "{Invalid maximum value for secondary input.}");
+									errors.append(service.getName() + "," + service.getAuthority()
+											+ "{Invalid maximum value for secondary input.}");
 									errors.append(newline);
 									continue;
 								}
 							}
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.min)) {
+							if (parameter.hasProperty(ServiceDescriptionPredicates.min)) {
 								try {
-									secondary
-											.setMinimumValue(Integer
-													.parseInt(parameter
-															.getProperty(
-																	ServiceDescriptionPredicates.min)
-															.getLiteral()
-															.getValue()
-															.toString()));
+									secondary.setMinimumValue(Integer.parseInt(parameter
+											.getProperty(ServiceDescriptionPredicates.min)
+											.getLiteral().getValue().toString()));
 								} catch (NumberFormatException e) {
 									success = false;
 									currentlyBad = true;
-									errors
-											.append(service.getName()
-													+ ","
-													+ service.getAuthority()
-													+ "{Invalid minimum value for secondary input.}");
+									errors.append(service.getName() + "," + service.getAuthority()
+											+ "{Invalid minimum value for secondary input.}");
 									errors.append(newline);
 									continue;
 								}
 							}
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.enumeration)) {
+							if (parameter.hasProperty(ServiceDescriptionPredicates.enumeration)) {
 								StmtIterator enumerations = parameter
 										.listProperties(ServiceDescriptionPredicates.enumeration);
 								while (enumerations.hasNext()) {
-									secondary.addAllowedValue(enumerations
-											.nextStatement().getLiteral()
-											.getValue().toString());
+									secondary.addAllowedValue(enumerations.nextStatement()
+											.getLiteral().getValue().toString());
 								}
 							}
 							service.addInput(secondary);
@@ -655,69 +595,62 @@
 					}
 				}
 
-				StmtIterator outputs = r
-						.listProperties(FetaVocabulary.outputParameter);
+				StmtIterator outputs = r.listProperties(FetaVocabulary.outputParameter);
 				while (outputs.hasNext()) {
-					Resource parameter = (Resource) outputs.nextStatement()
-							.getObject();
-					if (!parameter.getProperty(FetaVocabulary.hasParameterType)
-							.getResource().hasProperty(RDF.type)) {
+					Resource parameter = (Resource) outputs.nextStatement().getObject();
+					if (!parameter.getProperty(FetaVocabulary.hasParameterType).getResource()
+							.hasProperty(RDF.type)) {
 						success = false;
 						currentlyBad = true;
-						errors.append(service.getName() + ","
-								+ service.getAuthority()
-								+ "{Output for service "
-								+ service.getName()
+						errors.append(service.getName() + "," + service.getAuthority()
+								+ "{Output for service " + service.getName()
 								+ " did not have a parameter type of type RDF:type}");
 						errors.append(newline);
 						continue;
 					} else {
-						if (parameter.getProperty(
-								FetaVocabulary.hasParameterType).getResource()
-								.getProperty(RDF.type).getObject().toString()
-								.endsWith("simpleParameter")) {
+						if (parameter.getProperty(FetaVocabulary.hasParameterType).getResource()
+								.getProperty(RDF.type).getObject().toString().endsWith(
+										"simpleParameter")) {
 							// we have a simple
 							// make sure that object type and article name exist
-							if (!parameter
-									.hasProperty(ServiceDescriptionPredicates.object_type)) {
+							if (!parameter.hasProperty(ServiceDescriptionPredicates.object_type)) {
 								currentlyBad = true;
 								success = false;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Output for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Output for service " + service.getName()
 										+ " was missing an object type.}");
 								errors.append(newline);
 								continue;
 							}
-							if (!parameter
-									.hasProperty(FetaVocabulary.hasParameterNameText)) {
+							if (!parameter.hasProperty(FetaVocabulary.hasParameterNameText)) {
 								success = false;
 								currentlyBad = true;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Output for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Output for service " + service.getName()
 										+ " was missing an article name}");
 								errors.append(newline);
 								continue;
 							}
 
 							// name
-							String datatype = parameter.getProperty(
-									ServiceDescriptionPredicates.object_type)
-									.getObject().toString();
-							if (datatype.indexOf("#") > 0)
-								datatype = datatype.substring(datatype
-										.lastIndexOf("#") + 1);
-							// if (datatype.indexOf(":") > 0)
-							// datatype = datatype.substring(datatype
-							// .lastIndexOf(":") + 1);
+							LSID lsid = null;
+							try {
+								lsid = new LSID(parameter.getProperty(
+										ServiceDescriptionPredicates.object_type).getObject()
+										.toString());
+							} catch (MalformedLSIDException e) {
+								errors
+										.append("There was a problem extracting the output simple parameters' LSID "
+												+ e.getLocalizedMessage());
+								currentlyBad = true;
+								success = false;
+								continue;
+							}
 
+							String datatype = lsid.getObject();
 							// extract the article name
 							String articlename = parameter.getProperty(
-									FetaVocabulary.hasParameterNameText)
-									.getObject().toString();
+									FetaVocabulary.hasParameterNameText).getObject().toString();
 							if (articlename.equals("")) {
 								// throw new MobyException("Output for service "
 								// +
@@ -726,96 +659,91 @@
 							}
 							// check for namespaces
 							ArrayList namespaces = new ArrayList();
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
-								Resource namespaceResource = (Resource) parameter
-										.getProperty(
-												ServiceDescriptionPredicates.inNamespaces)
-										.getObject();
+							if (parameter.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
+								Resource namespaceResource = (Resource) parameter.getProperty(
+										ServiceDescriptionPredicates.inNamespaces).getObject();
 								StmtIterator namespaceIterator = namespaceResource
 										.listProperties(ServiceDescriptionPredicates.namespace_type);
 								while (namespaceIterator.hasNext()) {
-									String namespace = namespaceIterator
-											.nextStatement().getObject()
-											.toString();
-									if (namespace.indexOf("#") > 0)
-										namespace = namespace
-												.substring(namespace
-														.lastIndexOf("#") + 1);
-									// if (namespace.indexOf(":") > 0)
-									// namespace = namespace.substring(namespace
-									// .lastIndexOf(":") + 1);
+
+									LSID nsLSID = null;
+									try {
+										nsLSID = new LSID(namespaceIterator.nextStatement()
+												.getObject().toString());
+									} catch (MalformedLSIDException e) {
+										errors
+												.append("There was a problem extracting the parameters' LSID "
+														+ e.getLocalizedMessage());
+										currentlyBad = true;
+										success = false;
+										continue;
+									}
+
+									String namespace = nsLSID.getObject();
+
 									namespaces.add(namespace);
 								}
 							}
 							MobyPrimaryDataSimple primaryOutput = new MobyPrimaryDataSimple();
-							primaryOutput
-									.setDataType(new MobyDataType(datatype));
+							primaryOutput.setDataType(new MobyDataType(datatype));
 							primaryOutput.setName(articlename);
 							if (!namespaces.isEmpty()) {
-								for (Iterator nsIterator = namespaces
-										.iterator(); nsIterator.hasNext();) {
-									primaryOutput
-											.addNamespace(new MobyNamespace(
-													(String) nsIterator.next()));
+								for (Iterator nsIterator = namespaces.iterator(); nsIterator
+										.hasNext();) {
+									primaryOutput.addNamespace(new MobyNamespace(
+											(String) nsIterator.next()));
 								}
 							}
 							service.addOutput(primaryOutput);
-						} else if (parameter.getProperty(
-								FetaVocabulary.hasParameterType).getResource()
-								.getProperty(RDF.type).getObject().toString()
+						} else if (parameter.getProperty(FetaVocabulary.hasParameterType)
+								.getResource().getProperty(RDF.type).getObject().toString()
 								.endsWith("collectionParameter")) {
 							// we have a collection
 							// make sure that object type and article name exist
-							if (!parameter
-									.hasProperty(ServiceDescriptionPredicates.object_type)) {
+							if (!parameter.hasProperty(ServiceDescriptionPredicates.object_type)) {
 								success = false;
 								currentlyBad = true;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Collection Output for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection Output for service " + service.getName()
 										+ " was missing an object type.}");
 								errors.append(newline);
 								continue;
 							}
-							if (!parameter
-									.hasProperty(FetaVocabulary.hasParameterNameText)) {
+							if (!parameter.hasProperty(FetaVocabulary.hasParameterNameText)) {
 								success = false;
 								currentlyBad = true;
-								errors.append(service.getName() + ","
-										+ service.getAuthority()
-										+ "{Collection for service "
-										+ service.getName()
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection for service " + service.getName()
 										+ " was missing an article name.}");
 								errors.append(newline);
 								continue;
 							}
 							// name
-							String datatype = parameter.getProperty(
-									ServiceDescriptionPredicates.object_type)
-									.getObject().toString();
-							if (datatype.indexOf("#") > 0)
-								datatype = datatype.substring(datatype
-										.lastIndexOf("#") + 1);
-							// if (datatype.indexOf(":") > 0)
-							// datatype = datatype.substring(datatype
-							// .lastIndexOf(":") + 1);
+							LSID lsid = null;
+							try {
+								lsid = new LSID(parameter.getProperty(
+										ServiceDescriptionPredicates.object_type).getObject()
+										.toString());
+							} catch (MalformedLSIDException e) {
+								errors
+										.append("There was a problem extracting the output collection parameters' LSID "
+												+ e.getLocalizedMessage());
+								currentlyBad = true;
+								success = false;
+								continue;
+							}
+
+							String datatype = lsid.getObject();
 
 							// extract the article name
 							String articlename = parameter.getProperty(
-									FetaVocabulary.hasParameterNameText)
-									.getObject().toString();
+									FetaVocabulary.hasParameterNameText).getObject().toString();
 							if (articlename.equals("")) {
 								success = false;
 								currentlyBad = true;
-								errors
-										.append(service.getName()
-												+ ","
-												+ service.getAuthority()
-												+ "{Collection output for service "
-												+ service.getName()
-												+ " was missing a non empty article name.}");
+								errors.append(service.getName() + "," + service.getAuthority()
+										+ "{Collection output for service " + service.getName()
+										+ " was missing a non empty article name.}");
 								errors.append(newline);
 								continue;
 
@@ -823,25 +751,27 @@
 
 							// check for namespaces
 							ArrayList namespaces = new ArrayList();
-							if (parameter
-									.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
-								Resource namespaceResource = (Resource) parameter
-										.getProperty(
-												ServiceDescriptionPredicates.inNamespaces)
-										.getObject();
+							if (parameter.hasProperty(ServiceDescriptionPredicates.inNamespaces)) {
+								Resource namespaceResource = (Resource) parameter.getProperty(
+										ServiceDescriptionPredicates.inNamespaces).getObject();
 								StmtIterator namespaceIterator = namespaceResource
 										.listProperties(ServiceDescriptionPredicates.namespace_type);
 								while (namespaceIterator.hasNext()) {
-									String namespace = namespaceIterator
-											.nextStatement().getObject()
-											.toString();
-									if (namespace.indexOf("#") > 0)
-										namespace = namespace
-												.substring(namespace
-														.lastIndexOf("#") + 1);
-									// if (namespace.indexOf(":") > 0)
-									// namespace = namespace.substring(namespace
-									// .lastIndexOf(":") + 1);
+
+									LSID nsLSID = null;
+									try {
+										nsLSID = new LSID(namespaceIterator.nextStatement()
+												.getObject().toString());
+									} catch (MalformedLSIDException e) {
+										errors
+												.append("There was a problem extracting the parameters' LSID "
+														+ e.getLocalizedMessage());
+										currentlyBad = true;
+										success = false;
+										continue;
+									}
+
+									String namespace = nsLSID.getObject();
 									namespaces.add(namespace);
 								}
 							}
@@ -852,14 +782,13 @@
 										.get(articlename);
 							} else
 								collection = new MobyPrimaryDataSet(articlename);
-							MobyPrimaryDataSimple output = new MobyPrimaryDataSimple(
-									"");
+							MobyPrimaryDataSimple output = new MobyPrimaryDataSimple("");
 							output.setDataType(new MobyDataType(datatype));
 							if (!namespaces.isEmpty()) {
-								for (Iterator nsIterator = namespaces
-										.iterator(); nsIterator.hasNext();) {
-									output.addNamespace(new MobyNamespace(
-											(String) nsIterator.next()));
+								for (Iterator nsIterator = namespaces.iterator(); nsIterator
+										.hasNext();) {
+									output.addNamespace(new MobyNamespace((String) nsIterator
+											.next()));
 								}
 							}
 							collection.addElement(output);
@@ -875,8 +804,8 @@
 							.get((String) it.next()));
 				}
 				for (it = outputCollectionMap.keySet().iterator(); it.hasNext();) {
-					service.addOutput((MobyPrimaryDataSet) outputCollectionMap
-							.get((String) it.next()));
+					service.addOutput((MobyPrimaryDataSet) outputCollectionMap.get((String) it
+							.next()));
 				}
 			}
 			if (!currentlyBad)
@@ -893,8 +822,7 @@
 	 * @throws MobyException
 	 *             if there are any parsing errors
 	 */
-	public MobyService[] getMobyServicesFromRDF(String rdf)
-			throws MobyException {
+	public MobyService[] getMobyServicesFromRDF(String rdf) throws MobyException {
 
 		// lets start parsing
 		ArrayList list = new ArrayList();
@@ -924,8 +852,7 @@
 			this.url = url;
 		else {
 			this.url = null;
-			throw new MobyException("Invalid url specified by "
-					+ url.toExternalForm() + ".");
+			throw new MobyException("Invalid url specified by " + url.toExternalForm() + ".");
 		}
 	}
 
@@ -997,11 +924,10 @@
 		return errors.toString();
 	}
 
-	public static void main(String[] args) throws MobyException,
-			MalformedURLException, IOException {
+	public static void main(String[] args) throws MobyException, MalformedURLException, IOException {
 		// show how to use this class
 		ServiceInstanceParser p = new ServiceInstanceParser(
-				"http://bioinfo.icapture.ubc.ca:8090/RESOURCES/MOBY-S/ServiceInstances");
+				"http://bioinfo.icapture.ubc.ca/ekawas/services/parseBlastText.rdf");
 		MobyService[] services = p.getMobyServicesFromRDF();
 		if (!p.isRDFValid()) {
 			System.out.println("One or more services in the RDF were invalid");




More information about the MOBY-guts mailing list