[MOBY-guts] biomoby commit

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


gordonp
Wed Dec 13 12:53:57 EST 2006
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data
In directory dev.open-bio.org:/tmp/cvs-serv10329/src/main/org/biomoby/shared/data

Modified Files:
	MobyDataComposite.java MobyDataObject.java MobyDataXref.java 
Log Message:
Added support for cross-reference deserialization from XML
moby-live/Java/src/main/org/biomoby/shared/data MobyDataComposite.java,1.8,1.9 MobyDataObject.java,1.11,1.12 MobyDataXref.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.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/data/MobyDataComposite.java	2006/10/26 00:30:27	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java	2006/12/13 17:53:57	1.9
@@ -40,16 +40,26 @@
 	int numSubstructures = substructures.getLength();
 	for(int i = 0; i < numSubstructures; i++){
 	    org.w3c.dom.Element child = (org.w3c.dom.Element) substructures.item(i);
-	    // If the child element doesn't have a name, this
-	    // will be a problem for member association (i.e. it's an anonymous variable)
-	    String fieldName = getName(child);
-	    if(fieldName == null){
-		throw new IllegalArgumentException("The subelement with index " + i +
-						   " does not have an article " +
-						   "name, which is required");
+	    if(child.getLocalName().equals("CrossReference")){
+		addCrossReferences(child);
+	    }
+	    // Not yet implemented
+// 	    else if(child.getLocalName().equals("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)
+		String fieldName = getName(child);
+		if(fieldName == null || fieldName.length() == 0){
+		    throw new IllegalArgumentException("The subelement with index " + i +
+						       " does not have an article " +
+						       "name, which is required");
+		}
+		
+		// TODO, must deal with 1-to-many HAS relationship
+		children.put(fieldName, (MobyDataObject) createInstanceFromDOM(child));
 	    }
-	    // TODO, must deal with 1-to-many HAS relationship
-	    children.put(fieldName, (MobyDataObject) createInstanceFromDOM(child));
 	}
 
 	putAll(children);

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java	2006/10/30 15:54:39	1.11
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java	2006/12/13 17:53:57	1.12
@@ -381,9 +381,39 @@
 	return "[Object]";
     }
 
+    public void addCrossReferences(Element e) throws MobyException{
+	if(e == null){
+	    throw new NullPointerException("Cannot add a null cross-reference element to an object");
+	}
+	if(e.getLocalName() == null){
+	    throw new NullPointerException("Element name is null when trying to add cross-reference element");
+	}
+	if(!e.getLocalName().equals("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);
+	    }
+	    else if("Xref".equals(objectClass)){
+		new MobyDataXref(child);
+	    }
+	    else{
+		throw new MobyException("Cross-reference block contained an illegal child element ("+objectClass+
+					"), only 'Object' and 'Xref' are allowed");
+	    }
+	}
+    }
+
     public void addCrossReference(MobyDataObject mdsi) throws NullPointerException{
 	if(mdsi == null){
-	    throw new NullPointerException("Cannot add a null crossreference to an object");
+	    throw new NullPointerException("Cannot add a null cross-reference to an object");
 	}
 
 	// Hasn't been initialized yet?

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataXref.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/shared/data/MobyDataXref.java	2006/07/07 04:12:40	1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataXref.java	2006/12/13 17:53:57	1.6
@@ -65,6 +65,21 @@
 	getService().setAuthority(authURI);
     }
 
+    public MobyDataXref(Element e) throws MobyException{
+	this(getNamespace(e).getName(), 
+	     getId(e), 
+	     MobyPrefixResolver.getAttr(e, "serviceName"), 
+	     MobyPrefixResolver.getAttr(e, "authURI"));
+
+	setEvidenceCode(MobyPrefixResolver.getAttr(e, "evidenceCode"));
+	setXrefType(MobyPrefixResolver.getAttr(e, "xrefType"));
+
+	String d = e.getTextContent();
+	if(d != null && d.length() > 0){
+	    setDescription(d);
+	}
+    }
+
     /**
      * Build an Xref based on an existing object.
      * The namespace and id will be kept, everything else ignored as they don't 




More information about the MOBY-guts mailing list