[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Dec 13 23:15:58 UTC 2006


gordonp
Wed Dec 13 18:15:58 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data
In directory dev.open-bio.org:/tmp/cvs-serv11431/src/main/org/biomoby/shared/data

Modified Files:
	MobyDataComposite.java MobyDataObject.java 
	MobyProvisionInfo.java 
Log Message:
Use more MobyTags values instead of hardcoding, added ProvisionInformation deserialization support
moby-live/Java/src/main/org/biomoby/shared/data MobyDataComposite.java,1.9,1.10 MobyDataObject.java,1.12,1.13 MobyProvisionInfo.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java	2006/12/13 17:53:57	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java	2006/12/13 23:15:58	1.10
@@ -15,6 +15,7 @@
 import org.biomoby.shared.MobyNamespace;
 import org.biomoby.shared.MobyPrefixResolver;
 import org.biomoby.shared.MobyRelationship;
+import org.biomoby.shared.parser.MobyTags;
 
 /**
  * This class implements the ConcurrentMap interface to allow for the easy
@@ -40,13 +41,12 @@
 	int numSubstructures = substructures.getLength();
 	for(int i = 0; i < numSubstructures; i++){
 	    org.w3c.dom.Element child = (org.w3c.dom.Element) substructures.item(i);
-	    if(child.getLocalName().equals("CrossReference")){
+	    if(child.getLocalName().equals(MobyTags.CROSSREFERENCE)){
 		addCrossReferences(child);
 	    }
-	    // Not yet implemented
-// 	    else if(child.getLocalName().equals("ProvisionInformation")){
-// 		addProvisionInfo(child);		
-// 	    }
+ 	    else if(child.getLocalName().equals(MobyTags.PROVISIONINFORMATION)){
+ 		addProvisionInfo(child);		
+ 	    }
 	    else{
 		// If the child element doesn't have a name, this
 		// will be a problem for member association (i.e. it's an anonymous variable)

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java	2006/12/13 17:53:57	1.12
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java	2006/12/13 23:15:58	1.13
@@ -17,6 +17,7 @@
 import org.w3c.dom.NodeList;
 
 import org.biomoby.shared.*;
+import org.biomoby.shared.parser.MobyTags;
 
 /**
  * A class representing a MOBY object that has been instantiated.  
@@ -53,7 +54,7 @@
      */
     public MobyDataObject(String name){
         super(name);
-	setDataType(MobyDataType.getDataType("Object"));
+	setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT));
     }
 
     /**
@@ -61,7 +62,7 @@
      */
     public MobyDataObject(String namespace, String id){
 	super("");
-	setDataType(MobyDataType.getDataType("Object"));
+	setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT));
 	setId(id);	
 
 	MobyNamespace nsObj = MobyNamespace.getNamespace(namespace);
@@ -94,22 +95,22 @@
 	    return null;
 	}
 
-	if("Object".equals(typeName)){
+	if(MobyTags.MOBYOBJECT.equals(typeName)){
 	    return new MobyDataObject("", value);
 	}
-	else if("Integer".equals(typeName)){
+	else if(MobyTags.MOBYINTEGER.equals(typeName)){
 	    return new MobyDataInt("", value);
 	}
-	else if("Float".equals(typeName)){
+	else if(MobyTags.MOBYFLOAT.equals(typeName)){
 	    return new MobyDataFloat("", value);
 	}
-	else if("String".equals(typeName)){
+	else if(MobyTags.MOBYSTRING.equals(typeName)){
 	    return new MobyDataString("", value);
 	}
-	else if("Boolean".equals(typeName)){
+	else if(MobyTags.MOBYBOOLEAN.equals(typeName)){
 	    return new MobyDataBoolean("", value);
 	}
-	else if("DateTime".equals(typeName)){
+	else if(MobyTags.MOBYDATETIME.equals(typeName)){
 	    return new MobyDataDateTime("", value);
 	}
 	else if("text-base64".equals(typeName)){
@@ -139,7 +140,7 @@
 	}
 
 	String objectClass = objectTag.getLocalName();
-	if("Simple".equals(objectClass)){
+	if(MobyTags.SIMPLE.equals(objectClass)){
 	    Element elementChild = MobyPrefixResolver.getChildElement(objectTag, "*");
 	    // A Simple tag is allowed to have exactly one child element
 	    if(elementChild == null){
@@ -153,28 +154,28 @@
 
 	// There are six types of objects we can populate with data directly
 	// plus Collections and Secondary Parameters.  Otherwise it is a composite.
-	else if("Object".equals(objectClass)){
+	else if(MobyTags.MOBYOBJECT.equals(objectClass)){
 	    return new MobyDataObject(objectTag);	    
 	}
-	else if("Integer".equals(objectClass)){
+	else if(MobyTags.MOBYINTEGER.equals(objectClass)){
 	    return new MobyDataInt(objectTag);
 	}
-	else if("Float".equals(objectClass)){
+	else if(MobyTags.MOBYFLOAT.equals(objectClass)){
 	    return new MobyDataFloat(objectTag);
 	}
-	else if("String".equals(objectClass)){
+	else if(MobyTags.MOBYSTRING.equals(objectClass)){
 	    return new MobyDataString(objectTag);
 	}
-	else if("Boolean".equals(objectClass)){
+	else if(MobyTags.MOBYBOOLEAN.equals(objectClass)){
 	    return new MobyDataBoolean(objectTag);
 	}
-	else if("DateTime".equals(objectClass)){
+	else if(MobyTags.MOBYDATETIME.equals(objectClass)){
 	    return new MobyDataDateTime(objectTag);
 	}
 	else if("text-base64".equals(objectClass)){
 	    return new MobyDataBytes(objectTag);
 	}
-	else if("Collection".equals(objectClass)){
+	else if(MobyTags.COLLECTION.equals(objectClass)){
 	    return new MobyDataObjectSet(objectTag);
 	}
 	else if(MobyDataSecondaryInstance.ELEMENT_NAME.equals(objectClass)){
@@ -223,13 +224,13 @@
 	Node p = e.getParentNode();
 	String name = null;
 	// A top level object whose name is in the enclosing simple tag
-	if(p != null && (p instanceof Element) && ((Element) p).getTagName().equals("Simple")){
-	    name = MobyPrefixResolver.getAttr((Element) p, "articleName");
+	if(p != null && (p instanceof Element) && ((Element) p).getTagName().equals(MobyTags.SIMPLE)){
+	    name = MobyPrefixResolver.getAttr((Element) p, MobyTags.ARTICLENAME);
 	    return name == null ? "" : name;
 	}
 	// Part of a composite, subobject's name is in its own tag
 	else{
-	    name = MobyPrefixResolver.getAttr(e, "articleName");
+	    name = MobyPrefixResolver.getAttr(e, MobyTags.ARTICLENAME);
 	    return name == null ? "" : name;
 	}
     }
@@ -388,25 +389,24 @@
 	if(e.getLocalName() == null){
 	    throw new NullPointerException("Element name is null when trying to add cross-reference element");
 	}
-	if(!e.getLocalName().equals("CrossReference")){
+	if(!e.getLocalName().equals(MobyTags.CROSSREFERENCE)){
 	    throw new NullPointerException("Cannot add an element named '"+e.getLocalName()+
 					   "' as a CrossReference element");
 	}
-
 	NodeList substructures = MobyPrefixResolver.getChildElements(e, "*"); //wildcard
 	int numSubstructures = substructures.getLength();
 	for(int i = 0; i < numSubstructures; i++){
 	    Element child = (Element) substructures.item(i);
 	    String objectClass = child.getLocalName();
-	    if("Object".equals(objectClass)){
-		new MobyDataObject(child);
+	    if(MobyTags.MOBYOBJECT.equals(objectClass)){
+		addCrossReference(new MobyDataObject(child));
 	    }
-	    else if("Xref".equals(objectClass)){
-		new MobyDataXref(child);
+	    else if(MobyTags.XREF.equals(objectClass)){
+		addCrossReference(new MobyDataXref(child));
 	    }
 	    else{
 		throw new MobyException("Cross-reference block contained an illegal child element ("+objectClass+
-					"), only 'Object' and 'Xref' are allowed");
+					"), only '"+MobyTags.MOBYOBJECT+"' and '"+MobyTags.XREF+"' are allowed");
 	    }
 	}
     }
@@ -451,6 +451,20 @@
 	return CRIBVector != null && !CRIBVector.isEmpty();
     }
 
+    public void addProvisionInfo(Element e) throws MobyException{
+	if(e == null){
+	    throw new NullPointerException("Cannot add a null provision information element to an object");
+	}
+	if(e.getLocalName() == null){
+	    throw new NullPointerException("Element name is null when trying to add provision information element");
+	}
+	if(!e.getLocalName().equals(MobyTags.PROVISIONINFORMATION)){
+	    throw new NullPointerException("Cannot add an element named '"+e.getLocalName()+
+					   "' as a ProvisionInformation element");
+	}
+	setProvisionInfo(new MobyProvisionInfo(e));	
+    }
+
     public void setProvisionInfo(MobyProvisionInfo info){
 	provisionInfo = info;
     }
@@ -547,7 +561,7 @@
 	}
 
 	StringBuffer crib = new StringBuffer();
-	crib.append("<CrossReference>\n");
+	crib.append("<"+MobyTags.CROSSREFERENCE+">\n");
 
 	java.util.Iterator iter = CRIBVector.iterator();
 	while(iter != null && iter.hasNext()){
@@ -564,7 +578,7 @@
 		crib.append(obj.toXML()+"\n");
 	    }
 	}
-	crib.append("</CrossReference>\n");
+	crib.append("</"+MobyTags.CROSSREFERENCE+">\n");
 	return crib.toString();
     }
 
@@ -593,7 +607,7 @@
                 // If the data type is null, there must be something wrong
                 // with fetching the ontology RDF from MOBY Central.  At the very
                 // least, we know the thing must be an Object.
-                return "<Object " + getAttrXML() + "/>";
+                return "<"+MobyTags.MOBYOBJECT+" " + getAttrXML() + "/>";
             }
             else{
 	        return "<" + getDataType().getName() +" " + getAttrXML() + "/>";
@@ -604,7 +618,7 @@
 	    // but will cause cache misses for MOBY Central calls since the xml 
 	    // is used as a key in the call cache.
 	    StringBuffer buf = new StringBuffer();
-	    buf.append ("<Simple articleName=\"not_important\">\n");
+	    buf.append ("<"+MobyTags.SIMPLE+" articleName=\"not_important\">\n");
 	    buf.append ("<objectType>");
 	    if (getDataType() != null) buf.append (getDataType().getName());
 	    buf.append ("</objectType>\n");
@@ -618,7 +632,7 @@
 		    }
 		}
 	    }
-	    buf.append ("</Simple>");
+	    buf.append ("</"+MobyTags.SIMPLE+">");
 	    buf.append ("\n");
 	    return buf.toString();
 	    //return super.toXML();

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyProvisionInfo.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/shared/data/MobyProvisionInfo.java	2006/07/07 04:12:40	1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyProvisionInfo.java	2006/12/13 23:15:58	1.4
@@ -1,7 +1,9 @@
 
 package org.biomoby.shared.data;
 
+import org.biomoby.shared.MobyPrefixResolver;
 import org.biomoby.shared.parser.MobyTags;
+import org.w3c.dom.Element;
 
 /**
  * Class to hold data corresponginf to the MOBY PIB.
@@ -15,7 +17,39 @@
     private String dbVersion;
     private String dbComment;
     private String serviceComment;
+
+    /**
+     * Creates a blank provision information object.
+     */
+    public MobyProvisionInfo(){
+    }
     
+    /**
+     * Builds a provision information block from an XML fragment 
+     * ("ProvisionInformation", as represented by a DOM node).
+     */
+    public MobyProvisionInfo(Element e){
+	Element child = MobyPrefixResolver.getChildElement(e, MobyTags.SERVICESOFTWARE);
+	// all three child elements are optional.
+	if(child != null){
+	    setSoftwareName(MobyPrefixResolver.getAttr(child, MobyTags.SOFTWARENAME));
+	    setSoftwareVersion(MobyPrefixResolver.getAttr(child, MobyTags.SOFTWAREVERSION));
+	    setSoftwareComment(MobyPrefixResolver.getAttr(child, MobyTags.SOFTWARECOMMENT));
+	}
+
+	child = MobyPrefixResolver.getChildElement(e, MobyTags.SERVICEDATABASE);
+	// all three child elements are optional.
+	if(child != null){
+	    setSoftwareName(MobyPrefixResolver.getAttr(child, MobyTags.DATABASENAME));
+	    setSoftwareVersion(MobyPrefixResolver.getAttr(child, MobyTags.DATABASEVERSION));
+	    setSoftwareComment(MobyPrefixResolver.getAttr(child, MobyTags.DATABASECOMMENT));
+	}
+	child = MobyPrefixResolver.getChildElement(e, MobyTags.SERVICECOMMENT);
+	if(child != null){
+	    setComment(child.getTextContent());
+	}
+    }
+
     public void setSoftwareName(String name){
 	softwareName = name;
     }




More information about the MOBY-guts mailing list