[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue Jun 9 18:53:56 UTC 2009


gordonp
Tue Jun  9 14:53:55 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended
In directory dev.open-bio.org:/tmp/cvs-serv19316/src/main/org/biomoby/shared/extended

Modified Files:
	DataTypeParser.java 
Log Message:
Added ability to provide input as a stream instead of as a URL
moby-live/Java/src/main/org/biomoby/shared/extended DataTypeParser.java,1.13,1.14
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java	2008/02/28 17:00:12	1.13
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java	2009/06/09 18:53:55	1.14
@@ -1,5 +1,6 @@
 package org.biomoby.shared.extended;
 
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -39,6 +40,7 @@
 public class DataTypeParser {
 
 	private URL url = null;
+	private InputStream ins = null;
 
 	/**
 	 * Default constructor - need to set the URL for the RDF document that
@@ -135,6 +137,17 @@
 		return url;
 	}
 
+        /**
+	 * If not null, overrides the URL when reading the definitions (e.g. if you have the RDF as a String, not a URL use this).
+         */
+        public void setInputStream(InputStream is){
+	    ins = is;
+	}
+
+        public InputStream getInputStream(){
+	    return ins;
+        }
+
 	/**
 	 * 
 	 * @return an array of MobyServiceType objects created by parsing the RDF
@@ -144,18 +157,27 @@
 	 *             Data Type ontology is invalid
 	 */
 	public MobyDataType[] getMobyDataTypesFromRDF() throws MobyException {
-		// if url is invalid let client know
-		if (this.url == null)
-			throw new MobyException(
-					"Invalid url specified for the location of the RDF document that describes the Data Type ontology: "
-							+ this.url);
+	        InputStream is = null;
+	        if(ins != null){
+		    is = ins;
+	        }
+	        // if url is invalid let client know
+	        else{
+		    if (this.url == null){
+		        throw new MobyException(
+		  			        "Invalid url specified for the location of the "
+						+ "RDF document that describes the Data Type ontology: "
+					        + this.url);
+		    }
+		    is = Utils.getInputStream(getUrl());
+	        }
 
 		// lets start parsing
 		ArrayList<MobyDataType> list = new ArrayList<MobyDataType>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
-		reader.read(model,Utils.getInputStream(getUrl()), null);
+		reader.read(model, is, null);
 		ResIterator iterator = model.listSubjects();
 		while (iterator.hasNext()) {
 			Resource resource = iterator.nextResource();




More information about the MOBY-guts mailing list