[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Wed Mar 15 16:22:38 UTC 2006


kawas
Wed Mar 15 11:22:37 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority
In directory pub.open-bio.org:/tmp/cvs-serv32102/org/biomoby/client/ui/graphical/servlet/lsid/authority

Modified Files:
	MobyAuthority.java LSIDAuthorityMetaData.java 
	LSIDDataLookup.java 
Log Message:
updated RDF generators and clients so that LSIDs with versioining information is used. This is only preliminary. More updates to come

moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority MobyAuthority.java,1.4,1.5 LSIDAuthorityMetaData.java,1.3,1.4 LSIDDataLookup.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/MobyAuthority.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/MobyAuthority.java	2006/02/27 23:53:57	1.4
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/MobyAuthority.java	2006/03/15 16:22:37	1.5
@@ -57,11 +57,9 @@
 		return new LSIDMetadataPort[] {
 				new SOAPLocation("BioMOBYMetadataSOAPPort", "http://"
 						+ properties.getProperty("lsid_domain") + ":"
-						+ properties.getProperty("lsid_port")
-						+ "/authority/metadata"),
-				new HTTPLocation("BioMOBYMetadataHTTPPort", properties
-						.getProperty("lsid_domain"), Integer
-						.parseInt(properties.getProperty("lsid_port")),
+						+ properties.getProperty("lsid_port") + "/authority/metadata"),
+				new HTTPLocation("BioMOBYMetadataHTTPPort", properties.getProperty("lsid_domain"),
+						Integer.parseInt(properties.getProperty("lsid_port")),
 						"/authority/metadata") };
 	}
 
@@ -77,12 +75,9 @@
 		return new LSIDDataPort[] {
 				new SOAPLocation("BioMOBYDataSOAPPort", "http://"
 						+ properties.getProperty("lsid_domain") + ":"
-						+ properties.getProperty("lsid_port")
-						+ "/authority/data"),
-				new HTTPLocation("BioMOBYDataHTTPPort", properties
-						.getProperty("lsid_domain"), Integer
-						.parseInt(properties.getProperty("lsid_port")),
-						"/authority/data") };
+						+ properties.getProperty("lsid_port") + "/authority/data"),
+				new HTTPLocation("BioMOBYDataHTTPPort", properties.getProperty("lsid_domain"),
+						Integer.parseInt(properties.getProperty("lsid_port")), "/authority/data") };
 	}
 
 	/*
@@ -90,8 +85,7 @@
 	 * 
 	 * @see com.ibm.lsid.server.LSIDAuthorityService#getAvailableServices(com.ibm.lsid.server.LSIDRequestContext)
 	 */
-	public ExpiringResponse getAvailableServices(LSIDRequestContext ctx)
-			throws LSIDServerException {
+	public ExpiringResponse getAvailableServices(LSIDRequestContext ctx) throws LSIDServerException {
 		LSID lsid = ctx.getLsid();
 		String url = ctx.getReqUrl();
 		try {
@@ -109,8 +103,7 @@
 			return new ExpiringResponse(wsdl.toString(), getExpiration());
 		} catch (LSIDException e) {
 			throw new LSIDServerException(e, e.getErrorCode(),
-					"Simple Authority Error in getAvailableOperations(" + lsid
-							+ "): ");
+					"Simple Authority Error in getAvailableOperations(" + lsid + "): ");
 		}
 	}
 
@@ -119,19 +112,26 @@
 	 * 
 	 * @see com.ibm.lsid.server.LSIDService#initService(com.ibm.lsid.server.LSIDServiceConfig)
 	 */
-	public void initService(LSIDServiceConfig config)
-			throws LSIDServerException {
+	public void initService(LSIDServiceConfig config) throws LSIDServerException {
 		lookup = new LSIDDataLookup();
 		try {
+
 			Context c = new InitialContext();
-			String LSID_SERVER = (String) c
-					.lookup("java:comp/env/LSID_SERVER");
-			String LSID_PORT = (String) c.lookup("java:comp/env/LSID_PORT");
-			if (LSID_SERVER != null && !LSID_SERVER.equals("")) {
-				properties.setProperty("lsid_domain", LSID_SERVER);
+			try {
+				String LSID_SERVER = (String) c.lookup("java:comp/env/LSID_SERVER");
+
+				if (LSID_SERVER != null && !LSID_SERVER.equals("")) {
+					properties.setProperty("lsid_domain", LSID_SERVER);
+				}
+			} catch (Exception ex) {
 			}
-			if (LSID_PORT != null && !LSID_PORT.equals("")) {
-				properties.setProperty("lsid_port", LSID_PORT);
+
+			try {
+				String LSID_PORT = (String) c.lookup("java:comp/env/LSID_PORT");
+				if (LSID_PORT != null && !LSID_PORT.equals("")) {
+					properties.setProperty("lsid_port", LSID_PORT);
+				}
+			} catch (Exception ex) {
 			}
 
 		} catch (Exception e) {

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDAuthorityMetaData.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDAuthorityMetaData.java	2005/08/31 23:57:34	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDAuthorityMetaData.java	2006/03/15 16:22:37	1.4
@@ -1,10 +1,10 @@
-
 package org.biomoby.client.ui.graphical.servlet.lsid.authority;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.Date;
 
-import org.biomoby.client.rdf.builder.RDFConfigure;
+import org.biomoby.client.rdf.builder.ServiceInstanceRDF;
 
 import com.ibm.lsid.MetadataResponse;
 import com.ibm.lsid.server.LSIDMetadataService;
@@ -29,112 +29,113 @@
  *         email me at edward.kawas at gmail.com
  */
 public class LSIDAuthorityMetaData implements LSIDMetadataService {
-    private LSIDDataLookup lookup = null;
-    
+	private LSIDDataLookup lookup = null;
+
+	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
+		lookup = new LSIDDataLookup();
+	}
+
+	public MetadataResponse getMetadata(LSIDRequestContext req, String[] acceptedFormats)
+			throws LSIDServerException {
+		byte[] data = null;
+		int lsType;
+		try {
+			lsType = lookup.lsidType(req.getLsid());
+		} catch (LSIDServerException ex) {
+			ex.printStackTrace();
+			lsType = LSIDDataLookup.UNKNOWN;
+		}
+		if (lsType == LSIDDataLookup.UNKNOWN)
+			throw new LSIDServerException(201, "Error in getMetaData: Unknown LSID: "
+					+ req.getLsid());
+
+		switch (lsType) {
+		case LSIDDataLookup.NAMESPACE_TYPE: {
+			/* type is namespace */
+			try {
+				data = lookup.lsidLookup[1].retrieveObjectRDF(req.getLsid().toString());
+				
+			} catch (IOException e) {
+				throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR,
+						"Could not process RESOURCES.");
+			}
+			if (data == null)
+				throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE,
+						"No metadata is available");
+
+		}
+			break;
+		case LSIDDataLookup.OBJECT_CLASS: {
+			try {
+				/* type is object */
+				data = lookup.lsidLookup[0].retrieveObjectRDF(req.getLsid().toString());
+
+			} catch (IOException e) {
+				throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR,
+						"Could not process RESOURCES.");
+			}
+			if (data == null)
+				throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE,
+						"No metadata is available");
+
+		}
+			break;
+		case LSIDDataLookup.SERVICE_TYPE: {
+			/* type is service */
+			try {
+				data = lookup.lsidLookup[2].retrieveObjectRDF(req.getLsid().toString());
+			} catch (IOException e) {
+				throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR,
+						"Could not process RESOURCES.");
+			}
+			if (data == null)
+				throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE,
+						"No metadata is available");
+
+		}
+			break;
+		case LSIDDataLookup.SERVICE_RELATION:
+		case LSIDDataLookup.OBJECT_RELATION:
+		/* type is relationship */
+		{
+			if (data == null)
+				throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE,
+						"No metadata is available");
+		}
+			break;
+		case LSIDDataLookup.SERVICE_INSTANCE:
+		/* type is serviceinstance */
+		{
+			try {
+				data = lookup.lsidLookup[3].retrieveServiceInstanceRDF(req.getLsid().toString());
+			} catch (IOException e) {
+				throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR,
+						"Could not process RESOURCES.");
+			}
+			if (data == null)
+				throw new LSIDServerException(LSIDServerException.NO_METADATA_AVAILABLE,
+						"No metadata is available");
+
+		}
+			break;
+		case LSIDDataLookup.MOBY_PREDICATE:
+		/* type is rdfpredicate */{
+			// TODO - find the predicate that was requested.
+		}
+			break;
+		default:
+			throw new LSIDServerException(201, "1. Unknown LSID");
+		}
+		return new MetadataResponse(new ByteArrayInputStream(data), new Date(),
+				MetadataResponse.RDF_FORMAT);
+	}
+
+	private String makeFirstUpperCase(String name) {
+		if (name.length() <= 1)
+			return name.toUpperCase();
+		char[] letters = name.toCharArray();
+		letters[0] = Character.toUpperCase(letters[0]);
+		return new String(letters);
+	}
 
-    public void initService(LSIDServiceConfig cf) throws LSIDServerException {
-        lookup = new LSIDDataLookup();
-    }
-    
-
-    public MetadataResponse getMetadata(LSIDRequestContext req,
-            String[] acceptedFormats) throws LSIDServerException {
-        byte[] data = null;
-        int lsType;
-        try {
-            lsType = lookup.lsidType(req.getLsid());
-        } catch (LSIDServerException ex) {
-            ex.printStackTrace();
-            lsType = LSIDDataLookup.UNKNOWN;
-        }
-        if (lsType == LSIDDataLookup.UNKNOWN)
-            throw new LSIDServerException(201, "Error in getMetaData: Unknown LSID: " + req.getLsid());
-
-        switch (lsType) {
-            case LSIDDataLookup.NAMESPACE_TYPE: {
-                /* type is namespace */                
-                try {
-                    data = lookup.lsidLookup[1].retrieveObjectRDF(RDFConfigure.URI_NAMESPACE+req.getLsid().getObject());
-                } catch (IOException e) {
-                    throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR, "Could not process RESOURCES.");
-                }
-                if (data == null)
-                    throw new LSIDServerException(
-                            LSIDServerException.NO_METADATA_AVAILABLE,
-                            "No metadata is available");
-
-            }
-                break;
-            case LSIDDataLookup.OBJECT_CLASS: {
-                try {
-                    /* type is object */
-                    data = lookup.lsidLookup[0].retrieveObjectRDF(RDFConfigure.URI_OBJECT+req.getLsid().getObject());
-                } catch (IOException e) {
-                    throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR, "Could not process RESOURCES.");
-                }
-                if (data == null)
-                    throw new LSIDServerException(
-                            LSIDServerException.NO_METADATA_AVAILABLE,
-                            "No metadata is available");
-
-            }
-                break;
-            case LSIDDataLookup.SERVICE_TYPE: {
-                /* type is service */
-                try {
-                    data = lookup.lsidLookup[2].retrieveObjectRDF(RDFConfigure.URI_SERVICE+req.getLsid().getObject());
-                } catch (IOException e) {
-                    throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR, "Could not process RESOURCES.");
-                }
-                if (data == null)
-                    throw new LSIDServerException(
-                            LSIDServerException.NO_METADATA_AVAILABLE,
-                            "No metadata is available");
-
-            }
-                break;
-            case LSIDDataLookup.SERVICE_RELATION:
-            case LSIDDataLookup.OBJECT_RELATION:
-            /* type is relationship */
-            {
-                if (data == null)
-                    throw new LSIDServerException(
-                            LSIDServerException.NO_METADATA_AVAILABLE,
-                            "No metadata is available");
-            }
-                break;
-            case LSIDDataLookup.SERVICE_INSTANCE:
-                /* type is serviceinstance */
-            {
-                try {
-                    data = lookup.lsidLookup[3].retrieveServiceInstanceRDF(RDFConfigure.URI_ServiceINSTANCE+req.getLsid().getObject());
-                } catch (IOException e) {
-                    throw new LSIDServerException(LSIDServerException.INTERNAL_PROCESSING_ERROR, "Could not process RESOURCES.");
-                }
-                if (data == null)
-                    throw new LSIDServerException(
-                            LSIDServerException.NO_METADATA_AVAILABLE,
-                            "No metadata is available");
-
-            }
-                break;
-            case LSIDDataLookup.MOBY_PREDICATE:
-            /* type is rdfpredicate */{
-            	//TODO - find the predicate that was requested.
-            }
-                break;
-            default:
-                throw new LSIDServerException(201, "1. Unknown LSID");
-        }
-        return new MetadataResponse(new ByteArrayInputStream(data), new Date(), MetadataResponse.RDF_FORMAT);
-    }
-
-    private String makeFirstUpperCase(String name) {
-        if (name.length() <= 1)
-            return name.toUpperCase();
-        char[] letters = name.toCharArray();
-        letters[0] = Character.toUpperCase(letters[0]);
-        return new String(letters);
-    }
-    
 }
\ No newline at end of file

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDDataLookup.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDDataLookup.java	2006/02/27 23:51:43	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/ui/graphical/servlet/lsid/authority/LSIDDataLookup.java	2006/03/15 16:22:37	1.6
@@ -16,6 +16,7 @@
  */
 
 package org.biomoby.client.ui.graphical.servlet.lsid.authority;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Properties;
@@ -28,197 +29,218 @@
 import com.ibm.lsid.server.LSIDServerException;
 
 public class LSIDDataLookup {
-    
-    public static final int UNKNOWN = -1;
 
-    public static final int NAMESPACE_TYPE = 0;
+	public static final int UNKNOWN = -1;
 
-    public static final int OBJECT_CLASS = 1;
+	public static final int NAMESPACE_TYPE = 0;
 
-    public static final int SERVICE_TYPE = 2;
+	public static final int OBJECT_CLASS = 1;
 
-    public static final int SERVICE_RELATION = 3;
-
-    public static final int OBJECT_RELATION = 4;
-
-    public static final int SERVICE_INSTANCE = 5;
-
-    public static final int MOBY_PREDICATE = 6;
-    
-    private Properties mobycentral = MobyProperties.SERVICE_INSTANCE_PROPERTIES();
-    private Properties mobyobject = MobyProperties.OBJECT_PROPERTIES();
-    private Properties mobyservice = MobyProperties.SERVICE_PROPERTIES();
-    private Properties mobynamespace = MobyProperties.NAMESPACE_PROPERTIES();
-    private Properties mobyrelationship = MobyProperties.RELATIONSHIP_PROPERTIES();
-    
-    /**
-     * 0 - object
-     * 1 - namespace
-     * 2 - service
-     * 3 - service instance
-     * 
-     */
-    public RDFConfigure lsidLookup[] = {null,null,null,null};
-    
-    
-    public LSIDDataLookup() {
-                
-    }
-    
-    /**
-     * 
-     * @param lsid an lsid to check whether we have 'data' on it or not
-     * @return true if getData has actual data under the namespace of the lsid. False otherwise. 
-     */
-    public boolean isValidDataType (LSID lsid) {
-        String ns = lsid.getNamespace();
-        if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace")) || ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace")))
-                return true;
-        return false;
-    }
-    
-
-    public int dataLsidType(LSID lsid) {
-        String ns = lsid.getNamespace();
-        String id = lsid.getObject();
-        String ver = lsid.getRevision();
-        /*if (ver != null || (ver != null && ver.length() != 0))
-            return UNKNOWN;*/
-        if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace"))) {
-            return LSIDDataLookup.OBJECT_CLASS;
-        }
-        if (ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace"))) {
-            return LSIDDataLookup.SERVICE_INSTANCE;
-        }        
-        return UNKNOWN;
-    }
-    
-    public int lsidType(LSID lsid) throws LSIDServerException {
-        String ns = lsid.getNamespace();
-        String id = lsid.getObject();
-        String ver = lsid.getRevision();
-        int result = UNKNOWN;
-        String authority = lsid.getAuthority().getAuthority();
-
-        /*if (ver != null || (ver != null && ver.length() != 0))
-            return UNKNOWN;*/
-
-        if (ns.equalsIgnoreCase(mobynamespace.getProperty("lsid_namespace"))) {
-            //if (lsidLookup[1] == null) {
-                if (!authority.equals(mobynamespace.getProperty("lsid_authority"))) {
-                    throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
-                }
-                try {
-                    lsidLookup[1] = new RDFConfigure(RDFConfigure.URI_NAMESPACE);
-                } catch (IOException e) {
-                    throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
-                }
-            //}
-            if (lsidLookup[1].objectExists(lsid.getObject()))
-                result = NAMESPACE_TYPE;
-        }
-        else if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace"))) {
-            //if (lsidLookup[0] == null) {
-                if (!authority.equals(mobyobject.getProperty("lsid_authority"))) {
-                    throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
-                }
-                try {
-                    lsidLookup[0] = new RDFConfigure(RDFConfigure.URI_OBJECT);
-                } catch (IOException e) {
-                    throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
-                }
-           // }
-            if (lsidLookup[0].objectExists(lsid.getObject()))    
-                result = OBJECT_CLASS;
-        }
-        else if (ns.equalsIgnoreCase(mobyservice.getProperty("lsid_namespace"))) {
-           // if (lsidLookup[2] == null) {
-                if (!authority.equals(mobyservice.getProperty("lsid_authority"))) {
-                    throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
-                }
-                try {
-                    lsidLookup[2] = new RDFConfigure(RDFConfigure.URI_SERVICE);
-                } catch (IOException e) {
-                    throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
-                }
-           // }
-            if (lsidLookup[2].objectExists(lsid.getObject()))
-                result = SERVICE_TYPE;
-        }
-        else if (ns.equalsIgnoreCase("objectrelation")){
-
-        }
-        else if (ns.equalsIgnoreCase("servicerelation")) {
-
-        }
-        else if (ns.equalsIgnoreCase("rdfpredicates")) {
-            if (isValidPredicate(id)) {
-                return MOBY_PREDICATE;
-            }
-            return UNKNOWN;
-            
-        }
-        else if (ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace"))) {
-            String str = lsid.getObject();
-            // make sure that the service instance is in the form
-            // domain,serviceInstanceName
-          //  if (lsidLookup[3] == null) {
-                if (!authority.equals(mobycentral.getProperty("lsid_authority"))) {
-                    throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
-                }
-                try {
-                    lsidLookup[3] = new RDFConfigure(RDFConfigure.URI_ServiceINSTANCE);
-                } catch (IOException e) {
-                    throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
-                }
-         //   }
-            String[] parsed = str.split(",");
-            if (parsed.length != 2)
-                throw new LSIDServerException(LSIDServerException.UNKNOWN_LSID, "Unknown Service Instance LSID. Form should be urn:lsid:biomoby.org:serviceinstance:authorsURI,serviceInstanceName");
-            if (ServiceInstanceRDF.serviceInstanceExists(parsed[0],parsed[1]))
-                result = SERVICE_INSTANCE;
-        }
-        else
-            return UNKNOWN;
-        
-        return result;
-    }
-
-    
-    /*
-     * a hash of known predicates.
-     */
-    private final HashMap known_predicates = new HashMap();
-    
-    /*
-     * method to init the hash of known predicates.
-     * TODO - add new rdfpredicates here!
-     */
-    private void initHash() {
-        // add the objects that are valid for the namespace rdfpredicates
-        known_predicates.put("mobyOntology", "A phrase representing one of the bioMoby ontologies.");
-        known_predicates.put("mobyontology", "A phrase representing one of the bioMoby ontologies.");        
-    }
-    /**
-     *  
-     * <b>PRE:</b>the key is in the known_predicates<p>
-     * <b>POST:</b>the value that is mapped to the specific key is returned<p>
-     * @param key - a valid key contained in known_predicates.
-     * @return - the value that is mapped to the the key.
-     */
-    public String getKnownValue(String key) {
-        return (String) known_predicates.get(key);
-    }
-    
-    /**
-     *  
-     * <b>PRE:</b>None.<p>
-     * <b>POST:</b>If pred is a valid predicate, true is returned, otherwise false is returned<p>
-     * @param pred - the predicate to check for
-     * @return true if pred is a valid predicate, false otherwise.
-     */
-    public boolean isValidPredicate(String pred) {
-        return known_predicates.containsKey(pred);
-    }
-}
+	public static final int SERVICE_TYPE = 2;
 
+	public static final int SERVICE_RELATION = 3;
+
+	public static final int OBJECT_RELATION = 4;
+
+	public static final int SERVICE_INSTANCE = 5;
+
+	public static final int MOBY_PREDICATE = 6;
+
+	private Properties mobycentral = MobyProperties.SERVICE_INSTANCE_PROPERTIES();
+
+	private Properties mobyobject = MobyProperties.OBJECT_PROPERTIES();
+
+	private Properties mobyservice = MobyProperties.SERVICE_PROPERTIES();
+
+	private Properties mobynamespace = MobyProperties.NAMESPACE_PROPERTIES();
+
+	private Properties mobyrelationship = MobyProperties.RELATIONSHIP_PROPERTIES();
+
+	/**
+	 * 0 - object 1 - namespace 2 - service 3 - service instance
+	 * 
+	 */
+	public RDFConfigure lsidLookup[] = { null, null, null, null };
+
+	public LSIDDataLookup() {
+
+	}
+
+	/**
+	 * 
+	 * @param lsid
+	 *            an lsid to check whether we have 'data' on it or not
+	 * @return true if getData has actual data under the namespace of the lsid.
+	 *         False otherwise.
+	 */
+	public boolean isValidDataType(LSID lsid) {
+		String ns = lsid.getNamespace();
+		if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace"))
+				|| ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace")))
+			return true;
+		return false;
+	}
+
+	public int dataLsidType(LSID lsid) {
+		String ns = lsid.getNamespace();
+		String id = lsid.getObject();
+		String ver = lsid.getRevision();
+		/*
+		 * if (ver != null || (ver != null && ver.length() != 0)) return
+		 * UNKNOWN;
+		 */
+		if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace"))) {
+			return LSIDDataLookup.OBJECT_CLASS;
+		}
+		if (ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace"))) {
+			return LSIDDataLookup.SERVICE_INSTANCE;
+		}
+		return UNKNOWN;
+	}
+
+	public int lsidType(LSID lsid) throws LSIDServerException {
+		String ns = lsid.getNamespace();
+		String id = lsid.getObject();
+		String ver = lsid.getRevision();
+		int result = UNKNOWN;
+		String authority = lsid.getAuthority().getAuthority();
+
+		/*
+		 * if (ver != null || (ver != null && ver.length() != 0)) return
+		 * UNKNOWN;
+		 */
+
+		if (ns.equalsIgnoreCase(mobynamespace.getProperty("lsid_namespace"))) {
+			// if (lsidLookup[1] == null) {
+			if (!authority.equals(mobynamespace.getProperty("lsid_authority"))) {
+				throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
+			}
+			try {
+				lsidLookup[1] = new RDFConfigure(RDFConfigure.URI_NAMESPACE);
+			} catch (IOException e) {
+				throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
+			}
+			// }
+			if (lsidLookup[1].objectExists(lsid.toString()))
+				result = NAMESPACE_TYPE;
+			else if (lsidLookup[1].objectExisted(lsid.getObject()))
+				result = NAMESPACE_TYPE;
+		} else if (ns.equalsIgnoreCase(mobyobject.getProperty("lsid_namespace"))) {
+			// if (lsidLookup[0] == null) {
+			if (!authority.equals(mobyobject.getProperty("lsid_authority"))) {
+				throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
+			}
+			try {
+				lsidLookup[0] = new RDFConfigure(RDFConfigure.URI_OBJECT);
+			} catch (IOException e) {
+				throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
+			}
+			// }
+			if (lsidLookup[0].objectExists(lsid.toString()))
+				result = OBJECT_CLASS;
+			else if (lsidLookup[0].objectExisted(lsid.getObject()))
+				result = OBJECT_CLASS;
+		} else if (ns.equalsIgnoreCase(mobyservice.getProperty("lsid_namespace"))) {
+			// if (lsidLookup[2] == null) {
+			if (!authority.equals(mobyservice.getProperty("lsid_authority"))) {
+				throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
+			}
+			try {
+				lsidLookup[2] = new RDFConfigure(RDFConfigure.URI_SERVICE);
+			} catch (IOException e) {
+				throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
+			}
+			// }
+			if (lsidLookup[2].objectExists(lsid.toString()))
+				result = SERVICE_TYPE;
+			else if (lsidLookup[2].objectExists(lsid.getObject()))
+				result = SERVICE_TYPE;
+		} else if (ns.equalsIgnoreCase("objectrelation")) {
+
+		} else if (ns.equalsIgnoreCase("servicerelation")) {
+
+		} else if (ns.equalsIgnoreCase("rdfpredicates")) {
+			if (isValidPredicate(id)) {
+				return MOBY_PREDICATE;
+			}
+			return UNKNOWN;
+
+		} else if (ns.equalsIgnoreCase(mobycentral.getProperty("lsid_namespace"))) {
+			String str = lsid.getObject();
+			// make sure that the service instance is in the form
+			// domain,serviceInstanceName
+			// if (lsidLookup[3] == null) {
+			if (!authority.equals(mobycentral.getProperty("lsid_authority"))) {
+				throw new LSIDServerException("Error in lsidType - Unknown LSID: " + lsid.getLsid());
+			}
+			try {
+				lsidLookup[3] = new RDFConfigure(RDFConfigure.URI_ServiceINSTANCE);
+			} catch (IOException e) {
+				throw new LSIDServerException(500, "Server cannot find RESOURCE RDF");
+			}
+			// }
+
+			String[] parsed = str.split(",");
+			if (parsed.length != 2)
+				throw new LSIDServerException(
+						LSIDServerException.UNKNOWN_LSID,
+						"Unknown Service Instance LSID. Form should be urn:lsid:biomoby.org:serviceinstance:authorsURI,serviceInstanceName:version");
+			if (ServiceInstanceRDF.serviceInstanceExists(parsed[0], parsed[1], lsid.toString()))
+				result = SERVICE_INSTANCE;
+			else if (ServiceInstanceRDF.serviceInstanceExists(parsed[0], parsed[1]))
+				result = SERVICE_INSTANCE;
+
+		} else
+			return UNKNOWN;
+
+		return result;
+	}
+
+	/*
+	 * a hash of known predicates.
+	 */
+	private final HashMap known_predicates = new HashMap();
+
+	/*
+	 * method to init the hash of known predicates. TODO - add new rdfpredicates
+	 * here!
+	 */
+	private void initHash() {
+		// add the objects that are valid for the namespace rdfpredicates
+		known_predicates
+				.put("mobyOntology", "A phrase representing one of the bioMoby ontologies.");
+		known_predicates
+				.put("mobyontology", "A phrase representing one of the bioMoby ontologies.");
+	}
+
+	/**
+	 * 
+	 * <b>PRE:</b>the key is in the known_predicates
+	 * <p>
+	 * <b>POST:</b>the value that is mapped to the specific key is returned
+	 * <p>
+	 * 
+	 * @param key -
+	 *            a valid key contained in known_predicates.
+	 * @return - the value that is mapped to the the key.
+	 */
+	public String getKnownValue(String key) {
+		return (String) known_predicates.get(key);
+	}
+
+	/**
+	 * 
+	 * <b>PRE:</b>None.
+	 * <p>
+	 * <b>POST:</b>If pred is a valid predicate, true is returned, otherwise
+	 * false is returned
+	 * <p>
+	 * 
+	 * @param pred -
+	 *            the predicate to check for
+	 * @return true if pred is a valid predicate, false otherwise.
+	 */
+	public boolean isValidPredicate(String pred) {
+		return known_predicates.containsKey(pred);
+	}
+}




More information about the MOBY-guts mailing list