[MOBY-guts] biomoby commit

Eddie Kawas kawas at dev.open-bio.org
Fri Nov 7 17:26:35 UTC 2008


kawas
Fri Nov  7 12:26:34 EST 2008
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder
In directory dev.open-bio.org:/tmp/cvs-serv29819/src/main/org/biomoby/client/rdf/builder

Modified Files:
	ServiceInstanceRDF.java 
Log Message:
added code to allow either a hash or forward slash in our URIs. (Preference for forward slash).

For instance, if you provide http://somedomain.com/serviceinstance as a URI, it will now either make the URI
http://somedomain.com/serviceinstance/ <- prefered
or
http://somedomain.com/serviceinstance#
moby-live/Java/src/main/org/biomoby/client/rdf/builder ServiceInstanceRDF.java,1.37,1.38
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java	2008/02/20 16:58:59	1.37
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/rdf/builder/ServiceInstanceRDF.java	2008/11/07 17:26:34	1.38
@@ -1,7 +1,9 @@
 package org.biomoby.client.rdf.builder;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.util.HashMap;
+import java.io.InputStream;
+import java.security.MessageDigest;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -19,6 +21,7 @@
 import org.biomoby.shared.MobyResourceRef;
 import org.biomoby.shared.MobySecondaryData;
 import org.biomoby.shared.MobyService;
+import org.biomoby.shared.MobyUnitTest;
 import org.biomoby.shared.data.MobyDataSecondaryInstance;
 
 import com.hp.hpl.jena.rdf.model.Model;
@@ -44,6 +47,7 @@
  *         <p>
  *         email me at edward.kawas at gmail.com
  */
+ at SuppressWarnings("unchecked")
 public class ServiceInstanceRDF {
 
     // some URIs
@@ -58,28 +62,21 @@
 	    + "  </rdf:Description>"
 	    + System.getProperty("line.separator") + "</rdf:RDF>";
 
-    private static Map<String,String> URI_MAP = new HashMap<String,String>();
-
     private static Log log = LogFactory.getLog(ServiceInstanceRDF.class);
 
-    private static final String DCP = DC_PROTEGE.getURI();
-
-    private Registry registry = null;
-
     private CentralImpl central = null;
 
     // character is a has
-    private String trailing_character = "#";
-
+    private String[] trailing_characters = new String[]{"/","#"};
+    
+    private static String PREFERED_TRAILING_CHARACTER = null;
+    
     private String OBJ;
 
     private String SRV;
 
     private String NS;
 
-    private String MP = "http://biomoby.org/RESOURCES/MOBY-S/Predicates"
-	    + trailing_character;
-
     private String SI;
 
     public final String getLatestLSID(String uri, String name, String lsid) {
@@ -106,7 +103,9 @@
     }
 
     public static void main(String[] args) throws Exception {
-	System.out.println(new ServiceInstanceRDF().findService("bioinfo.icapture.ubc.ca", "", false));
+	System.out.println(new ServiceInstanceRDF().findService(
+		//"bioinfo.icapture.ubc.ca", "getGoTerm", true));
+		"atidb.org", "getInsertionsWithOffsetAsGFFByAGICode", true));
     }
 
     /**
@@ -190,44 +189,52 @@
      *                 if there is a problem communicating with the registry
      */
     public ServiceInstanceRDF(Registry reg) throws MobyException {
-	registry = reg;
 	central = new CentralImpl(reg.getEndpoint(), reg.getNamespace());
 	MobyResourceRef[] refs = central.getResourceRefs();
 	for (MobyResourceRef ref : refs) {
 	    if (ref.getResourceName().equals(
 		    CentralImpl.DATA_TYPES_RESOURCE_NAME)) {
 		OBJ = ref.getResourceLocation().toString();
-		if (!OBJ.endsWith(trailing_character))
-		    OBJ = OBJ + trailing_character;
+		OBJ = validateUri(OBJ);
 	    } else if (ref.getResourceName().equals(
 		    CentralImpl.SERVICE_INSTANCES_RESOURCE_NAME)) {
 		SI = ref.getResourceLocation().toString();
-		if (!SI.endsWith(trailing_character))
-		    SI = SI + trailing_character;
+		SI = validateUri(SI);
 	    } else if (ref.getResourceName().equals(
 		    CentralImpl.NAMESPACES_RESOURCE_NAME)) {
 		NS = ref.getResourceLocation().toString();
-		if (!NS.endsWith(trailing_character))
-		    NS = NS + trailing_character;
+		NS = validateUri(NS);
 	    } else if (ref.getResourceName().equals(
 		    CentralImpl.SERVICE_TYPES_RESOURCE_NAME)) {
 		SRV = ref.getResourceLocation().toString();
-		if (!SRV.endsWith(trailing_character))
-		    SRV = SRV + trailing_character;
+		SRV = validateUri(SRV);
 	    }
 	}
     }
 
-    /*
-     * method that actually creates the rdf based on one or more services
-     * contained in the array services
-     */
-    private final String createRDF(MobyService[] services) {
-	Model model = createRDFModel(ModelFactory.createDefaultModel(),
-		services, true);
-	return serializeModel(model);
+    private String validateUri(String string) {
+	boolean isValid = false;
+	for (String s : trailing_characters) {
+	    if (string.endsWith(s)) {
+		isValid = true;
+		if (PREFERED_TRAILING_CHARACTER == null)
+		    PREFERED_TRAILING_CHARACTER = s;
+		break;
+	    }
+	}
+	// our default trailing char
+	String trailer = "/";
+	if (PREFERED_TRAILING_CHARACTER != null)
+	    trailer = PREFERED_TRAILING_CHARACTER;
+	return isValid ? string : string + trailer;
     }
-    
+
+    /**
+     * 
+     * @param model
+     *                a jena model
+     * @return a string of RDF/XML-ABBREV representing the RDF model
+     */
     public final String serializeModel(Model model) {
 	FilteredStream stream = new FilteredStream(new ByteArrayOutputStream());
 	RDFWriter writer = model.getWriter("RDF/XML-ABBREV");
@@ -264,7 +271,7 @@
 	    model = ModelFactory.createDefaultModel();
 	}
 	// set up the prefixes/namespaces
-	Map<String,String> map = model.getNsPrefixMap();
+	Map<String, String> map = model.getNsPrefixMap();
 	map.put("mobyService", SRV);
 	map.put("mobyNamespace", NS);
 	map.put("mobyObject", OBJ);
@@ -290,17 +297,17 @@
 		    services[i].getDescription());
 	    subject.addProperty(FetaVocabulary.hasServiceNameText, services[i]
 		    .getName());
+
 	    if (useLSIDs)
 		subject.addProperty(DC_PROTEGE.identifier, services[i]
 			.getLSID());
-	    /*
-	     * subject.addProperty(ServiceDescriptionPredicates.hasServiceType,
-	     * services[i] .getType());
-	     */
 
 	    // create the organization node
-	    Resource publishedBy = model
-		    .createResource(FetaVocabulary.organisation);
+	    Resource publishedBy = model.createResource(SI
+		    + MD5Checksum.md5(services[i].getAuthority() + "/"
+			    + services[i].getName() + "/"
+			    + FetaVocabulary.providedBy.getURI()));
+	    publishedBy.addProperty(RDF.type, FetaVocabulary.organisation);
 	    publishedBy.addProperty(DC_PROTEGE.creator, services[i]
 		    .getEmailContact());
 	    publishedBy.addProperty(DC_PROTEGE.publisher, services[i]
@@ -310,16 +317,22 @@
 	    subject.addProperty(FetaVocabulary.providedBy, publishedBy);
 
 	    // add the inputs/outputs
-	    Resource hasOperation = model
-		    .createResource(FetaVocabulary.operation);
+	    Resource hasOperation = model.createResource(SI
+		    + MD5Checksum.md5(services[i].getAuthority() + "/"
+			    + services[i].getName() + "/"
+			    + FetaVocabulary.hasOperation.getURI()));
+	    hasOperation.addProperty(RDF.type, FetaVocabulary.operation);
 	    // add the hasOperation to the resource
 	    subject.addProperty(FetaVocabulary.hasOperation, hasOperation);
 	    hasOperation.addProperty(FetaVocabulary.hasOperationNameText,
 		    services[i].getName());
 
 	    // add the performsTask information
-	    Resource performs = model
-		    .createResource(FetaVocabulary.operationTask);
+	    Resource performs = model.createResource(SI
+		    + MD5Checksum.md5(services[i].getAuthority() + "/"
+			    + services[i].getName() + "/"
+			    + FetaVocabulary.performsTask.getURI()));
+	    performs.addProperty(RDF.type, FetaVocabulary.performsTask);
 	    // if service type is lsid, dont append to URI
 	    try {
 		new LSID(services[i].getServiceType().getName());
@@ -333,66 +346,129 @@
 
 	    hasOperation.addProperty(FetaVocabulary.performsTask, performs);
 
+	    // add any unit test information now
+	    if (services[i].getUnitTest() != null) {
+		MobyUnitTest mobyUnitTest = services[i].getUnitTest();
+        	Resource unitTest = model.createResource(SI
+        		+ MD5Checksum.md5(services[i].getAuthority()
+        		+ "/"
+        		+ services[i].getName()
+        		+ "/"
+        		+ FetaVocabulary.unitTest.getURI()));
+        	unitTest.addProperty(RDF.type, FetaVocabulary.unitTest);
+        	// add the example input if defined
+        	if (!mobyUnitTest.getExampleInput().trim().equals("")) {
+        	    unitTest.addProperty(FetaVocabulary.exampleInput, mobyUnitTest.getExampleInput());
+        	}
+        	// add the valid output xml if defined
+        	if (!mobyUnitTest.getValidOutputXML().trim().equals("")) {
+        	    unitTest.addProperty(FetaVocabulary.validOutputXML, mobyUnitTest.getValidOutputXML());
+        	}
+        	// add the valid regex if defined
+        	if (!mobyUnitTest.getValidREGEX().trim().equals("")) {
+        	    unitTest.addProperty(FetaVocabulary.validREGEX, mobyUnitTest.getValidREGEX());
+        	}
+        	// add the xpath expression if defined
+        	if (!mobyUnitTest.getValidXPath().trim().equals("")) {
+        	    unitTest.addProperty(FetaVocabulary.validXPath, mobyUnitTest.getValidXPath());
+        	}
+        	// add node to the graph
+        	hasOperation.addProperty(FetaVocabulary.hasUnitTest, unitTest);
+	    }
+	    
+	    
+	    
 	    if (primaryInputs.length > 0) {
 		for (int j = 0; j < primaryInputs.length; j++) {
 		    if (primaryInputs[j] instanceof MobyPrimaryDataSimple) {
 			MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) primaryInputs[j];
-			Resource parameter = model
-				.createResource(FetaVocabulary.parameter);
+			Resource parameter = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.inputParameter
+						.getURI() + "/"
+					+ simpleData.getName()));
+			parameter.addProperty(RDF.type,
+				FetaVocabulary.parameter);
 			parameter.addProperty(
 				FetaVocabulary.hasParameterNameText, simpleData
 					.getName());
-			parameter
-				.addProperty(
-					FetaVocabulary.hasParameterType,
-					model
-						.createResource(FetaVocabulary.simpleParameter));
-			// if object is lsid, dont append to URI
+			Resource pType = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.hasParameterType
+						.getURI() + "/"
+					+ simpleData.getName()));
+			pType.addProperty(RDF.type,
+				FetaVocabulary.simpleParameter);
+			parameter.addProperty(FetaVocabulary.hasParameterType,
+				pType);
 
+			boolean isLSID = false;
 			try {
-			    // an lsid
-			    Resource bnode = model.createResource();
 			    new LSID(simpleData.getDataType().getName());
-			    bnode.addProperty(RDF.type, model
-				    .createResource(simpleData.getDataType()
-					    .getName()));
-			    parameter.addProperty(FetaVocabulary.object_type,
-				    bnode);
-			} catch (MalformedLSIDException e) {
-			    // not an lsid
-			    Resource bnode = model.createResource();
-			    bnode.addProperty(RDF.type, model
-				    .createResource(OBJ
-					    + simpleData.getDataType()
-						    .getName()));
-			    parameter.addProperty(FetaVocabulary.object_type,
-				    bnode);
-
+			    isLSID = true;
+			} catch (MalformedLSIDException e1) {
+			    isLSID = false;
 			}
+			// create the resource
+			Resource bnode = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.inputParameter
+						.getURI() + "/"
+					+ simpleData.getName() + "/"
+					+ simpleData.getDataType().getName()));
+			bnode.addProperty(RDF.type, model
+				.createResource(isLSID ? simpleData
+					.getDataType().getName() : OBJ
+					+ simpleData.getDataType().getName()));
+			parameter
+				.addProperty(FetaVocabulary.object_type, bnode);
 
 			MobyNamespace[] namespaces = simpleData.getNamespaces();
 			if (namespaces.length > 0) {
-			    // Resource parameterNamespace = model
-			    // .createResource(FetaVocabulary.parameterNamespace);
-			    // parameter.addProperty(FetaVocabulary.inNamespaces,
-			    // parameterNamespace);
 			    for (int k = 0; k < namespaces.length; k++) {
 				// if namespace is lsid, dont append to URI
 				Resource parameterNamespace = model
-					.createResource(FetaVocabulary.parameterNamespace);
+					.createResource(SI
+						+ MD5Checksum
+							.md5(services[i]
+								.getAuthority()
+								+ "/"
+								+ services[i]
+									.getName()
+								+ "/isSimple/"
+								+ FetaVocabulary.inputParameter
+									.getURI()
+								+ "/"
+								+ simpleData
+									.getName()
+								+ "/"
+								+ namespaces[k]
+									.getName()));
+				parameterNamespace.addProperty(RDF.type,
+					FetaVocabulary.parameterNamespace);
 				parameter.addProperty(
 					FetaVocabulary.inNamespaces,
 					parameterNamespace);
+				isLSID = false;
 				try {
 				    new LSID(namespaces[k].getName());
-				    parameterNamespace.addProperty(RDF.type,
-					    model.createResource(namespaces[k]
-						    .getName()));
+				    isLSID = true;
 				} catch (MalformedLSIDException e) {
-				    parameterNamespace.addProperty(RDF.type,
-					    model.createResource(NS
-						    + namespaces[k].getName()));
+				    isLSID = false;
 				}
+				parameterNamespace.addProperty(RDF.type, model
+					.createResource(isLSID ? namespaces[k]
+						.getName() : NS
+						+ namespaces[k].getName()));
 			    }
 			}
 			hasOperation.addProperty(FetaVocabulary.inputParameter,
@@ -408,7 +484,21 @@
 			for (int k = 0; k < setOfSimpleData.length; k++) {
 			    if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
 				Resource parameter = model
-					.createResource(FetaVocabulary.parameter);
+					.createResource(
+						SI
+							+ MD5Checksum
+								.md5(services[i]
+									.getAuthority()
+									+ "/"
+									+ services[i]
+										.getName()
+									+ "/isCollection/"
+									+ FetaVocabulary.inputParameter
+										.getURI()
+									+ "/"
+									+ collectionName))
+					.addProperty(RDF.type,
+						FetaVocabulary.parameter);
 				parameter.addProperty(
 					FetaVocabulary.hasParameterNameText,
 					collectionName);
@@ -416,11 +506,41 @@
 					.addProperty(
 						FetaVocabulary.hasParameterType,
 						model
-							.createResource(FetaVocabulary.collectionParameter));
+							.createResource(
+								SI
+									+ MD5Checksum
+										.md5(services[i]
+											.getAuthority()
+											+ "/"
+											+ services[i]
+												.getName()
+											+ "/isCollection/"
+											+ FetaVocabulary.hasParameterType
+												.getURI()
+											+ "/"
+											+ collectionName))
+							.addProperty(
+								RDF.type,
+								FetaVocabulary.collectionParameter));
 				// if object is lsid, dont append to URI
 				try {
-
-				    Resource bnode = model.createResource();
+				    Resource bnode = model
+					    .createResource(SI
+						    + MD5Checksum
+							    .md5(services[i]
+								    .getAuthority()
+								    + "/"
+								    + services[i]
+									    .getName()
+								    + "/isCollection/"
+								    + FetaVocabulary.inputParameter
+									    .getURI()
+								    + "/"
+								    + collectionName
+								    + "/"
+								    + setOfSimpleData[k]
+									    .getDataType()
+									    .getName()));
 				    new LSID(setOfSimpleData[k].getDataType()
 					    .getName());
 				    bnode.addProperty(RDF.type, model
@@ -430,7 +550,23 @@
 					    FetaVocabulary.object_type, bnode);
 
 				} catch (MalformedLSIDException e) {
-				    Resource bnode = model.createResource();
+				    Resource bnode = model
+					    .createResource(SI
+						    + MD5Checksum
+							    .md5(services[i]
+								    .getAuthority()
+								    + "/"
+								    + services[i]
+									    .getName()
+								    + "/isCollection/"
+								    + FetaVocabulary.inputParameter
+									    .getURI()
+								    + "/"
+								    + collectionName
+								    +"/"
+								    + setOfSimpleData[k]
+									    .getDataType()
+									    .getName()));
 				    bnode.addProperty(RDF.type, model
 					    .createResource(OBJ
 						    + setOfSimpleData[k]
@@ -443,21 +579,32 @@
 				MobyNamespace[] namespaces = setOfSimpleData[k]
 					.getNamespaces();
 				if (namespaces.length > 0) {
-				    /*
-				     * Resource parameterNamespace = model
-				     * .createResource(FetaVocabulary.parameterNamespace);
-				     */
 				    for (int index = 0; index < namespaces.length; index++) {
 					// if namespace is lsid, dont
 					// append to URI
 					Resource parameterNamespace = model
-						.createResource(FetaVocabulary.parameterNamespace);
-					parameter.addProperty(
-						FetaVocabulary.inNamespaces,
-						parameterNamespace);
+						.createResource(SI
+							+ MD5Checksum
+								.md5(services[i]
+									.getAuthority()
+									+ "/"
+									+ services[i]
+										.getName()
+									+ "/isCollection/"
+									+ FetaVocabulary.inputParameter
+										.getURI()
+									+ "/"
+									+ collectionName
+									+ "/"
+									+ namespaces[k]
+										.getName()));
+					parameterNamespace
+						.addProperty(
+							RDF.type,
+							FetaVocabulary.parameterNamespace);
 					try {
-					    LSID theLSID = new LSID(
-						    namespaces[index].getName());
+					    new LSID(namespaces[index]
+						    .getName());
 					    parameterNamespace
 						    .addProperty(
 							    RDF.type,
@@ -473,6 +620,9 @@
 									    + namespaces[index]
 										    .getName()));
 					}
+					parameter.addProperty(
+						FetaVocabulary.inNamespaces,
+						parameterNamespace);
 
 				    }
 				    /*
@@ -503,13 +653,39 @@
 		for (int j = 0; j < secondaryInputs.length; j++) {
 		    if (secondaryInputs[j] instanceof MobySecondaryData) {
 			MobySecondaryData data = (MobySecondaryData) secondaryInputs[j];
-			Resource _li = model
-				.createResource(FetaVocabulary.parameter);
+			Resource _li = model.createResource(
+				SI
+					+ MD5Checksum.md5(services[i]
+						.getAuthority()
+						+ "/"
+						+ services[i].getName()
+						+ "/isSecondaryInputParameter/"
+						+ FetaVocabulary.inputParameter
+							.getURI()
+						+ "/"
+						+ data.getName())).addProperty(
+				RDF.type, FetaVocabulary.parameter);
 			_li
 				.addProperty(
 					FetaVocabulary.hasParameterType,
 					model
-						.createResource(FetaVocabulary.secondaryParameter));
+						.createResource(
+							SI
+								+ MD5Checksum
+									.md5(services[i]
+										.getAuthority()
+										+ "/"
+										+ services[i]
+											.getName()
+										+ "/isSecondary/"
+										+ FetaVocabulary.hasParameterType
+											.getURI()
+										+ "/"
+										+ data
+											.getName()))
+						.addProperty(
+							RDF.type,
+							FetaVocabulary.secondaryParameter));
 
 			if (!data.getName().equals(""))
 			    _li
@@ -565,53 +741,77 @@
 		for (int j = 0; j < outputs.length; j++) {
 		    if (outputs[j] instanceof MobyPrimaryDataSimple) {
 			MobyPrimaryDataSimple simpleData = (MobyPrimaryDataSimple) outputs[j];
-			Resource parameter = model
-				.createResource(FetaVocabulary.parameter);
+			Resource parameter = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.outputParameter
+						.getURI() + "/"
+					+ simpleData.getName()));
 			parameter.addProperty(
 				FetaVocabulary.hasParameterNameText, simpleData
 					.getName());
-			parameter
-				.addProperty(
-					FetaVocabulary.hasParameterType,
-					model
-						.createResource(FetaVocabulary.simpleParameter));
-			// if object is lsid, dont append to URI
+			Resource pType = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.hasParameterType
+						.getURI() + "/"
+					+ simpleData.getName()));
+			pType.addProperty(RDF.type,
+				FetaVocabulary.simpleParameter);
+			parameter.addProperty(FetaVocabulary.hasParameterType,
+				pType);
+
+			boolean isLSID = false;
 			try {
-			    Resource bnode = model.createResource();
 			    new LSID(simpleData.getDataType().getName());
-			    bnode.addProperty(RDF.type, model
-				    .createResource(simpleData.getDataType()
-					    .getName()));
-			    parameter.addProperty(FetaVocabulary.object_type,
-				    bnode);
-			} catch (MalformedLSIDException e) {
-			    Resource bnode = model.createResource();
-			    bnode.addProperty(RDF.type, model
-				    .createResource(OBJ
-					    + simpleData.getDataType()
-						    .getName()));
-			    parameter.addProperty(FetaVocabulary.object_type,
-				    bnode);
+			    isLSID = true;
+			} catch (MalformedLSIDException e1) {
+			    isLSID = false;
 			}
+			// create the resource
+			Resource bnode = model.createResource(SI
+				+ MD5Checksum.md5(services[i].getAuthority()
+					+ "/"
+					+ services[i].getName()
+					+ "/isSimple/"
+					+ FetaVocabulary.outputParameter
+						.getURI() + "/"
+					+ simpleData.getName() + "/"
+					+ simpleData.getDataType().getName()));
+			bnode.addProperty(RDF.type, model
+				.createResource(isLSID ? simpleData
+					.getDataType().getName() : OBJ
+					+ simpleData.getDataType().getName()));
+			parameter
+				.addProperty(FetaVocabulary.object_type, bnode);
 
 			MobyNamespace[] namespaces = simpleData.getNamespaces();
 			if (namespaces.length > 0) {
-			    /*
-			     * Resource parameterNamespace =
-			     * model.createResource(ModelFactory
-			     * .createDefaultModel().createProperty(
-			     * FetaVocabulary.getURI() + "parameterNamespace"));
-			     * parameter.addProperty(FetaVocabulary.inNamespaces,
-			     * parameterNamespace);
-			     */
 			    for (int k = 0; k < namespaces.length; k++) {
 				// if namespace is lsid, dont append to URI
 				Resource parameterNamespace = model
-					.createResource(ModelFactory
-						.createDefaultModel()
-						.createProperty(
-							FetaVocabulary.getURI()
-								+ "parameterNamespace"));
+					.createResource(SI
+						+ MD5Checksum
+							.md5(services[i]
+								.getAuthority()
+								+ "/"
+								+ services[i]
+									.getName()
+								+ "/isSimple/"
+								+ FetaVocabulary.outputParameter
+									.getURI()
+								+ "/"
+								+ simpleData
+									.getName()
+								+ "/"
+								+ namespaces[k]
+									.getName()));
+				parameterNamespace.addProperty(RDF.type,
+					FetaVocabulary.parameterNamespace);
 				parameter.addProperty(
 					FetaVocabulary.inNamespaces,
 					parameterNamespace);
@@ -640,18 +840,55 @@
 			for (int k = 0; k < setOfSimpleData.length; k++) {
 			    if (setOfSimpleData[k] instanceof MobyPrimaryDataSimple) {
 				Resource parameter = model
-					.createResource(FetaVocabulary.parameter);
+					.createResource(
+						SI
+							+ MD5Checksum
+								.md5(services[i]
+									.getAuthority()
+									+ "/"
+									+ services[i]
+										.getName()
+									+ "/isCollection/"
+									+ FetaVocabulary.outputParameter
+										.getURI()
+									+ "/"
+									+ collectionName))
+					.addProperty(RDF.type,
+						FetaVocabulary.parameter);
 				parameter.addProperty(
 					FetaVocabulary.hasParameterNameText,
 					collectionName);
-				parameter
-					.addProperty(
-						FetaVocabulary.hasParameterType,
-						model
-							.createResource(FetaVocabulary.collectionParameter));
+				Resource pType = model.createResource(SI
+					+ MD5Checksum.md5(services[i].getAuthority()
+						+ "/"
+						+ services[i].getName()
+						+ "/isCollection/"
+						+ FetaVocabulary.hasParameterType
+							.getURI() + "/"
+						+ collectionName));
+				pType.addProperty(RDF.type,
+					FetaVocabulary.collectionParameter);
+				parameter.addProperty(FetaVocabulary.hasParameterType,
+					pType);
 				// if object is lsid, dont append to URI
 				try {
-				    Resource bnode = model.createResource();
+				    Resource bnode = model
+					    .createResource(SI
+						    + MD5Checksum
+							    .md5(services[i]
+								    .getAuthority()
+								    + "/"
+								    + services[i]
+									    .getName()
+								    + "/isCollection/"
+								    + FetaVocabulary.outputParameter
+									    .getURI()
+								    + "/"
+								    + collectionName
+								    + "/"
+								    + setOfSimpleData[k]
+									    .getDataType()
+									    .getName()));
 				    new LSID(setOfSimpleData[k].getDataType()
 					    .getName());
 				    bnode.addProperty(RDF.type, model
@@ -660,7 +897,23 @@
 				    parameter.addProperty(
 					    FetaVocabulary.object_type, bnode);
 				} catch (MalformedLSIDException e) {
-				    Resource bnode = model.createResource();
+				    Resource bnode = model
+					    .createResource(SI
+						    + MD5Checksum
+							    .md5(services[i]
+								    .getAuthority()
+								    + "/"
+								    + services[i]
+									    .getName()
+								    + "/isCollection/"
+								    + FetaVocabulary.outputParameter
+									    .getURI()
+								    + "/"
+								    + collectionName
+								    + "/"
+								    + setOfSimpleData[k]
+									    .getDataType()
+									    .getName()));
 				    bnode.addProperty(RDF.type, model
 					    .createResource(OBJ
 						    + setOfSimpleData[k]
@@ -679,10 +932,28 @@
 				     */
 				    for (int index = 0; index < namespaces.length; index++) {
 					Resource parameterNamespace = model
-						.createResource(FetaVocabulary.parameterNamespace);
+						.createResource(SI
+							+ MD5Checksum
+								.md5(services[i]
+									.getAuthority()
+									+ "/"
+									+ services[i]
+										.getName()
+									+ "/isCollection/"
+									+ FetaVocabulary.outputParameter
+										.getURI()
+									+ "/"
+									+ collectionName
+									+ "/"
+									+ namespaces[k]
+										.getName()));
+					parameterNamespace
+						.addProperty(
+							RDF.type,
+							FetaVocabulary.parameterNamespace);
 					try {
-					    LSID theLSID = new LSID(
-						    namespaces[index].getName());
+					    new LSID(namespaces[index]
+						    .getName());
 					    parameterNamespace
 						    .addProperty(
 							    RDF.type,
@@ -730,6 +1001,39 @@
 	return model;
     }
 
+    private static class MD5Checksum {
+
+	private static byte[] createChecksum(String msg) {
+	    try {
+		InputStream fis = new ByteArrayInputStream(msg.getBytes());
+		byte[] buffer = new byte[1024];
+		MessageDigest complete = MessageDigest.getInstance("MD5");
+		int numRead;
+		do {
+		    numRead = fis.read(buffer);
+		    if (numRead > 0) {
+			complete.update(buffer, 0, numRead);
+		    }
+		} while (numRead != -1);
+		fis.close();
+		return complete.digest();
+	    } catch (Exception e) {
+
+	    }
+	    return "".getBytes();
+	}
+
+	public static String md5(String msg) {
+	    byte[] b = createChecksum(msg);
+	    String result = "";
+	    for (int i = 0; i < b.length; i++) {
+		result += Integer.toString((b[i] & 0xff) + 0x100, 16)
+			.substring(1);
+	    }
+	    return result;
+	}
+    }
+
     /**
      * 
      * <b>PRE: </b>name is either a valid name or null
@@ -737,7 +1041,7 @@
      * <b>POST: </b>If authorURI is a valid authority, then a RDF containing all
      * of the service instances will be returned. If authorURI and name are
      * valid then a single RDF containing just the service instance identified
-     * by name is returned. 
+     * by name is returned.
      * <p>
      * 
      * @param authorURI -
@@ -751,13 +1055,14 @@
      *         if name and authorURI are valid. If name and/or authorURI are
      *         invalid an empty rdf document is returned.
      */
-    public final String findService(String authorURI, String name, boolean useLSIDs) {
+    public final String findService(String authorURI, String name,
+	    boolean useLSIDs) {
 	if (name == null || name.trim().equals("")) {
-	    return (useLSIDs ? getAllServices(authorURI)
-		    : getAllServices(authorURI, false));
+	    return (useLSIDs ? getAllServices(authorURI) : getAllServices(
+		    authorURI, false));
 	} else {
-	    return (useLSIDs ? getService(authorURI, name)
-		    : getService(authorURI, name, false));
+	    return (useLSIDs ? getService(authorURI, name) : getService(
+		    authorURI, name, false));
 	}
     }
 
@@ -955,7 +1260,7 @@
      * a method that retrieves all of the service instances based on an
      * authoriy.
      */
-    private final String getAllServices(String URI,boolean useLSIDs) {
+    private final String getAllServices(String URI, boolean useLSIDs) {
 	// variables needed
 	MobyService service = null;
 	MobyService[] services = null;
@@ -998,7 +1303,7 @@
 	MobyService service = null;
 	MobyService[] services = null;
 	Central central = getCentralImpl();
-	
+
 	// set up the query service
 	service = new MobyService(name);
 	service.setCategory("");
@@ -1029,7 +1334,7 @@
 	MobyService service = null;
 	MobyService[] services = null;
 	Central central = getCentralImpl();
-	
+
 	// set up the query service
 	service = new MobyService(name);
 	service.setCategory("");




More information about the MOBY-guts mailing list