[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Thu Nov 29 16:59:04 UTC 2007


kawas
Thu Nov 29 11:59:04 EST 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended
In directory dev.open-bio.org:/tmp/cvs-serv30748/Java/src/main/org/biomoby/shared/extended

Modified Files:
	NamespaceParser.java ServiceInstanceParser.java 
	DataTypeParser.java ServiceTypeParser.java 
Log Message:
Changes include
*takes into account URIs that don't have '#' in them, but have '/'
*made code compliant with java1.5 so that warnings disappear

moby-live/Java/src/main/org/biomoby/shared/extended NamespaceParser.java,1.7,1.8 ServiceInstanceParser.java,1.20,1.21 DataTypeParser.java,1.7,1.8 ServiceTypeParser.java,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java	2006/04/27 14:47:37	1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/NamespaceParser.java	2007/11/29 16:59:04	1.8
@@ -149,7 +149,7 @@
 							+ this.url);
 
 		// lets start parsing
-		ArrayList list = new ArrayList();
+		ArrayList<MobyNamespace> list = new ArrayList<MobyNamespace>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
@@ -166,7 +166,9 @@
 			String name = "";
 			if (uri.indexOf("#") > 0)
 				name = uri.substring(uri.indexOf("#")+1);
-			
+			else if(uri.lastIndexOf("/Namespaces/") > 0) {
+			    name = uri.substring(uri.lastIndexOf("/Namepaces/")+"/Namespaces/".length());
+			}
 			
 			MobyNamespace namespace = new MobyNamespace(name);
 			if (resource.hasProperty(DC_PROTEGE.identifier)) {

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java	2006/12/07 16:37:36	1.20
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceInstanceParser.java	2007/11/29 16:59:04	1.21
@@ -8,7 +8,6 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.biomoby.client.rdf.vocabulary.DC_PROTEGE;
@@ -151,7 +150,7 @@
 							+ this.url);
 		}
 		// lets start parsing
-		ArrayList list = new ArrayList();
+		ArrayList<MobyService> list = new ArrayList<MobyService>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
@@ -176,7 +175,7 @@
 	 */
 	public MobyService[] getMobyServicesFromRDF(Model model) throws MobyException {
 		// clear out any old information
-		ArrayList list = new ArrayList();
+		ArrayList<MobyService> list = new ArrayList<MobyService>();
 		if (model != null) {
 			// lets start parsing
 			this.parsedOkay = processModel(list, model);
@@ -190,7 +189,7 @@
        /**
 	 * @param list the list to put the services in @param model the model to use
 	 */
-	private boolean processModel(ArrayList list, Model model) {
+	private boolean processModel(ArrayList<MobyService> list, Model model) {
 		// clear out any old information
 		this.parsedOkay = false;
 		this.errors = new StringBuffer();
@@ -240,8 +239,10 @@
 								String[] parsedServiceType = serviceType.split("#");
 								if (parsedServiceType.length == 2)
 									service.setType(parsedServiceType[1]);
-								else
-									service.setType(parsedServiceType[0]);
+								else if(serviceType.lastIndexOf("/Services/") > 0) {
+								    service.setType(serviceType.substring(serviceType.lastIndexOf("/Services/")+"/Services/".length()));
+								} else 
+								    service.setType(parsedServiceType[0]);
 							}
 						}
 					}
@@ -307,8 +308,8 @@
 				Resource r = (Resource) s.getObject();
 				StmtIterator inputs = r.listProperties(FetaVocabulary.inputParameter);
 				// collections to be added at the end the current scope
-				Map inputCollectionMap = new HashMap();
-				Map outputCollectionMap = new HashMap();
+				Map<String,MobyPrimaryDataSet> inputCollectionMap = new HashMap<String, MobyPrimaryDataSet>();
+				Map<String, MobyPrimaryDataSet> outputCollectionMap = new HashMap<String, MobyPrimaryDataSet>();
 				// is the current service bad?
 				while (inputs.hasNext()) {
 
@@ -367,7 +368,9 @@
 
 							if (datatype.indexOf("#") > 0)
 								datatype = datatype.substring(datatype.indexOf("#") + 1);
-
+							else if(datatype.lastIndexOf("/Objects/") > 0) {
+							    datatype = datatype.substring(datatype.lastIndexOf("/Objects/")+"/Objects/".length());
+							}
 							// extract the article name
 							String articlename = parameter.getProperty(
 									FetaVocabulary.hasParameterNameText).getObject().toString();
@@ -381,7 +384,7 @@
 								continue;
 							}
 							// check for namespaces
-							ArrayList namespaces = new ArrayList();
+							ArrayList<String> namespaces = new ArrayList<String>();
 							if (parameter.hasProperty(FetaVocabulary.inNamespaces)) {
 								StmtIterator namespaceIterator = parameter.listProperties(FetaVocabulary.inNamespaces);
 								while (namespaceIterator.hasNext()) {
@@ -395,6 +398,9 @@
 												continue;
 											if (ns.indexOf("#") > 0)
 												ns = ns.substring(ns.indexOf("#") + 1);
+											else if(ns.lastIndexOf("/Namespaces/") > 0) {
+											    ns = ns.substring(ns.lastIndexOf("/Namespaces/")+"/Namespaces/".length());
+											}
 											namespaces.add(ns);
 										}
 									}
@@ -405,10 +411,8 @@
 							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 (String ns : namespaces) {
+									primaryInput.addNamespace(new MobyNamespace(ns));
 								}
 							}
 							service.addInput(primaryInput);
@@ -458,6 +462,9 @@
 							}
 							if (datatype.indexOf("#") > 0)
 								datatype = datatype.substring(datatype.indexOf("#") + 1);
+							else if(datatype.lastIndexOf("/Objects/") > 0) {
+							    datatype = datatype.substring(datatype.lastIndexOf("/Objects/")+"/Objects/".length());
+							}
 
 							// extract the article name
 							String articlename = parameter.getProperty(
@@ -473,7 +480,7 @@
 							}
 
 							// check for namespaces
-							ArrayList namespaces = new ArrayList();
+							ArrayList<String> namespaces = new ArrayList<String>();
 							if (parameter.hasProperty(FetaVocabulary.inNamespaces)) {
 								StmtIterator namespaceIterator = parameter.listProperties(FetaVocabulary.inNamespaces);
 								while (namespaceIterator.hasNext()) {
@@ -487,6 +494,9 @@
 												continue;
 											if (ns.indexOf("#") > 0)
 												ns = ns.substring(ns.indexOf("#") + 1);
+											else if(ns.lastIndexOf("/Namespaces/") > 0) {
+											    ns = ns.substring(ns.lastIndexOf("/Namespaces/")+"/Namespaces/".length());
+											}
 											namespaces.add(ns);
 										}
 									}
@@ -503,11 +513,9 @@
 							MobyPrimaryDataSimple input = new MobyPrimaryDataSimple("");
 							input.setDataType(new MobyDataType(datatype));
 							if (!namespaces.isEmpty()) {
-								for (Iterator nsIterator = namespaces.iterator(); nsIterator
-										.hasNext();) {
+								for (String ns : namespaces) {
 									input
-											.addNamespace(new MobyNamespace((String) nsIterator
-													.next()));
+											.addNamespace(new MobyNamespace(ns));
 								}
 							}
 							collection.addElement(input);
@@ -684,7 +692,9 @@
 									.toString();*/
 							if (datatype.indexOf("#") > 0)
 								datatype = datatype.substring(datatype.indexOf("#") + 1);
-							
+							else if(datatype.lastIndexOf("/Objects/") > 0) {
+							    datatype = datatype.substring(datatype.lastIndexOf("/Objects/")+"/Objects/".length());
+							}
 							// extract the article name
 							String articlename = parameter.getProperty(
 									FetaVocabulary.hasParameterNameText).getObject().toString();
@@ -695,7 +705,7 @@
 								// article name");
 							}
 							// check for namespaces
-							ArrayList namespaces = new ArrayList();
+							ArrayList<String> namespaces = new ArrayList<String>();
 							if (parameter.hasProperty(FetaVocabulary.inNamespaces)) {
 								StmtIterator namespaceIterator = parameter.listProperties(FetaVocabulary.inNamespaces);
 								while (namespaceIterator.hasNext()) {
@@ -709,6 +719,9 @@
 												continue;
 											if (ns.indexOf("#") > 0)
 												ns = ns.substring(ns.indexOf("#") + 1);
+											else if(ns.lastIndexOf("/Namespaces/") > 0) {
+											    ns = ns.substring(ns.lastIndexOf("/Namespaces/")+"/Namespaces/".length());
+											}
 											namespaces.add(ns);
 										}
 									}
@@ -719,10 +732,8 @@
 							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 (String ns : namespaces) {
+									primaryOutput.addNamespace(new MobyNamespace(ns));
 								}
 							}
 							service.addOutput(primaryOutput);
@@ -773,7 +784,9 @@
 							
 							if (datatype.indexOf("#") > 0)
 								datatype = datatype.substring(datatype.indexOf("#") + 1);
-
+							else if(datatype.lastIndexOf("/Objects/") > 0) {
+							    datatype = datatype.substring(datatype.lastIndexOf("/Objects/")+"/Objects/".length());
+							}
 							// extract the article name
 							String articlename = parameter.getProperty(
 									FetaVocabulary.hasParameterNameText).getObject().toString();
@@ -789,7 +802,7 @@
 							}
 
 							// check for namespaces
-							ArrayList namespaces = new ArrayList();
+							ArrayList<String> namespaces = new ArrayList<String>();
 							if (parameter.hasProperty(FetaVocabulary.inNamespaces)) {
 								StmtIterator namespaceIterator = parameter.listProperties(FetaVocabulary.inNamespaces);
 								while (namespaceIterator.hasNext()) {
@@ -803,6 +816,9 @@
 												continue;
 											if (ns.indexOf("#") > 0)
 												ns = ns.substring(ns.indexOf("#") + 1);
+											else if(ns.lastIndexOf("/Namespaces/") > 0) {
+											    ns= ns.substring(ns.lastIndexOf("/Namespaces/")+"/Namespaces/".length());
+											}
 											namespaces.add(ns);
 										}
 									}
@@ -819,10 +835,8 @@
 							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 (String ns : namespaces) {
+									output.addNamespace(new MobyNamespace(ns));
 								}
 							}
 							collection.addElement(output);
@@ -832,14 +846,11 @@
 				}
 
 				// add the collections to the service
-				Iterator it = null;
-				for (it = inputCollectionMap.keySet().iterator(); it.hasNext();) {
-					service.addInput((MobyPrimaryDataSet) inputCollectionMap
-							.get((String) it.next()));
+				for (String key : inputCollectionMap.keySet()) {
+					service.addInput((MobyPrimaryDataSet) inputCollectionMap.get(key));
 				}
-				for (it = outputCollectionMap.keySet().iterator(); it.hasNext();) {
-					service.addOutput((MobyPrimaryDataSet) outputCollectionMap.get((String) it
-							.next()));
+				for (String key : outputCollectionMap.keySet()) {
+					service.addOutput((MobyPrimaryDataSet) outputCollectionMap.get(key));
 				}
 			}
 			if (!currentlyBad)
@@ -859,7 +870,7 @@
 	public MobyService[] getMobyServicesFromRDF(String rdf) throws MobyException {
 
 		// lets start parsing
-		ArrayList list = new ArrayList();
+		ArrayList<MobyService> list = new ArrayList<MobyService>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
@@ -960,8 +971,9 @@
 
 	public static void main(String[] args) throws MobyException, MalformedURLException, IOException {
 		// show how to use this class
-		ServiceInstanceParser p = new ServiceInstanceParser("http://localhost/ServiceInstance.rdf");
+		ServiceInstanceParser p = new ServiceInstanceParser("http://biomoby.org/RESOURCES/MOBY-S/ServiceInstances");
 		MobyService[] services = p.getMobyServicesFromRDF();
+		System.out.println(services.length);
 		if (!p.isRDFValid()) {
 			System.out.println("One or more services in the RDF were invalid");
 			System.out.println("The errors are the following:");

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java	2007/07/17 18:11:42	1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/DataTypeParser.java	2007/11/29 16:59:04	1.8
@@ -154,7 +154,7 @@
 							+ this.url);
 
 		// lets start parsing
-		ArrayList list = new ArrayList();
+		ArrayList<MobyDataType> list = new ArrayList<MobyDataType>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
@@ -173,12 +173,17 @@
 			String name = "";
 			if (uri.indexOf("#") > 0)
 				name = uri.substring(uri.indexOf("#")+1);
-			
+			else if(uri.lastIndexOf("/Objects/") > 0) {
+			    name = uri.substring(uri.lastIndexOf("/Objects/")+"/Objects/".length());
+			}
 			String parent = null;
 			if (resource.hasProperty(RDFS.subClassOf)) {
 				parent = ((Resource)resource.getProperty(RDFS.subClassOf).getObject()).getURI();
 				if (parent.indexOf("#") > 0)
 					parent = parent.substring(parent.indexOf("#")+1);
+				else if(parent.lastIndexOf("/Objects/") > 0) {
+				    parent = parent.substring(parent.lastIndexOf("/Objects/")+"/Objects/".length());
+				}
 			}
 			String description = resource.getProperty(RDFS.comment).getLiteral().getString();
 			// create the base datatype without container relationships

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceTypeParser.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceTypeParser.java	2006/04/27 14:47:37	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/extended/ServiceTypeParser.java	2007/11/29 16:59:04	1.9
@@ -147,7 +147,7 @@
 							+ this.url);
 
 		// lets start parsing
-		ArrayList list = new ArrayList();
+		ArrayList<MobyServiceType> list = new ArrayList<MobyServiceType>();
 		// create the model
 		Model model = ModelFactory.createDefaultModel();
 		RDFReader reader = model.getReader();
@@ -163,7 +163,9 @@
 			String name = "";
 			if (uri.indexOf("#") > 0)
 				name = uri.substring(uri.indexOf("#")+1);
-			
+			else if(uri.lastIndexOf("/Services/") > 0) {
+			    name = uri.substring(uri.lastIndexOf("/Services/")+"/Services/".length());
+			}
 			
 			MobyServiceType servicetype = new MobyServiceType(name);
 			if (resource.hasProperty(DC_PROTEGE.identifier)) {
@@ -177,6 +179,9 @@
 			String parent = resource.getProperty(RDFS.subClassOf).getObject().toString();
 			if (parent.indexOf("#") > 0)
 				parent = parent.substring(parent.indexOf("#")+1);
+			else if(parent.lastIndexOf("/Services/") > 0) {
+			    parent = parent.substring(parent.lastIndexOf("/Services/")+"/Services/".length());
+			}
 			servicetype.setParentNames(new String[] {parent});
 			String description = resource.getProperty(RDFS.comment).getLiteral().getString();
 			servicetype.setDescription(description);




More information about the MOBY-guts mailing list