[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Tue Jun 9 19:24:00 UTC 2009


gordonp
Tue Jun  9 15:24:00 EDT 2009
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services
In directory dev.open-bio.org:/tmp/cvs-serv20879/src/main/ca/ucalgary/seahawk/services

Modified Files:
	MobyComplexBuilder.java 
Log Message:
Added id support, use Apache XPath explicitly, better namespace support
moby-live/Java/src/main/ca/ucalgary/seahawk/services MobyComplexBuilder.java,1.15,1.16
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyComplexBuilder.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyComplexBuilder.java	2008/01/17 17:12:47	1.15
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyComplexBuilder.java	2009/06/09 19:24:00	1.16
@@ -2,9 +2,8 @@
 
 import org.biomoby.client.util.Base64Coder;
 import org.biomoby.shared.*;
-import org.biomoby.shared.data.MobyDataBytes;
-import org.biomoby.shared.data.MobyDataComposite;
-import org.biomoby.shared.data.MobyDataObject;
+import org.biomoby.shared.data.*;
+import org.biomoby.shared.parser.MobyTags;
 
 import org.w3c.dom.Document;
 
@@ -22,6 +21,7 @@
 public class MobyComplexBuilder{
     public static final String ANON_ARTICLE = "_seahawk_data";
     public static final String INHERITED_MEMBERS_SENTINEL = "_seahawk_member_inheritance";
+    public static final String PRIMITIVE_VALUE_SENTINEL = "__prim_field";
     private static XPathFactory xPathFactory;
     private static DocumentBuilder docBuilder;
 
@@ -32,9 +32,14 @@
     private MobyNamespace[] mobyNS;
     private MobyRelationship[] children;
     private MobyClient client;
+    private int context = 0;
+    private String srcURN = null;
 
     static{
-	xPathFactory = XPathFactory.newInstance();
+	//PG temporarily use xalan while Google App Engine has error
+        //xPathFactory = XPathFactory.newInstance();
+	xPathFactory = new org.apache.xpath.jaxp.XPathFactoryImpl();
+
 	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 	dbf.setNamespaceAware(true);
 	try{
@@ -60,7 +65,7 @@
 	client = cl;
 
 	if(mobyDataType != null && mobyDataType.getName() != null && 
-	   !mobyDataType.getName().equals("Object")){
+	   !mobyDataType.getName().equals(MobyTags.MOBYOBJECT)){
 	    children = mobyDataType.getAllChildren();
 	   
 	    // Make sure all fields are defined
@@ -168,7 +173,7 @@
     public MobyDataObject apply(Matcher matcher, byte[] data) throws MobyException{
 	MobyDataObject mobyObj = null;
 	
-	if(mobyDataType.getName().equals("Object")){
+	if(mobyDataType.getName().equals(MobyTags.MOBYOBJECT)){
 	    mobyObj = new MobyDataObject("", client.getRegistry());
 	}
 	else if(mobyDataType.inheritsFrom(MobyDataType.getDataType(MobyDataBytes.BASE64_DATATYPE, client.getRegistry()))){
@@ -499,9 +504,12 @@
 	xpath.setNamespaceContext(nsContext);
 	MobyDataObject mobyObj = null;
 	
-	if(mobyDataType.getName().equals("Object")){
+	if(mobyDataType.getName().equals(MobyTags.MOBYOBJECT)){
 	    mobyObj = new MobyDataObject("", client.getRegistry());
 	}
+	else if(mobyDataType.getName().equals(MobyTags.MOBYSTRING)){
+	    mobyObj = new MobyDataString("", client.getRegistry());
+	}
 	// else ifs for other primitives in the future maybe?
 	else{
 	    mobyObj = new MobyDataComposite(mobyDataType);
@@ -544,6 +552,11 @@
 		}
 	    }
 	}
+	else if(mobyObj instanceof MobyDataString){
+	    String expr = memberRules.get(PRIMITIVE_VALUE_SENTINEL)[0];
+	    ((MobyDataString) mobyObj).setValue(xpath.evaluate(expr, result));
+	}
+	// TODO handle integers and other primitives
 
 	return mobyObj;
     }
@@ -552,7 +565,36 @@
      * Reports the data type of the objects returned by matched rules.
      */
     public MobyDataType getDataType(){
-	//System.err.println("Returning data type of " + mobyDataType.getName());
 	return mobyDataType;
     }
+
+    /**
+     * Reports the possible namespaces of the objects returned by matched rules.
+     */
+    public MobyNamespace[] getNamespaces(){
+	return mobyNS;
+    }
+
+    /**
+     * Reports the URN identifying the rule, or null if it doesn't exist.  Useful for rule-sharing purposes.
+     */
+    public String getURN(){
+	return srcURN;
+    }
+
+    /**
+     * Call in order to provide a unique ID for the rule, for reuse purposes.
+     */
+    public void setURN(String urn){
+	srcURN = urn;
+    }
+
+    /**
+     * Call to find out if the result will be a String or NodeList, etc if there's an XPath.
+     *
+     * @return one of the constants (NODESET, STRING) from javax.xml.xpath.XPathConstants, or 0 if not an XPath rule
+     */
+    public int requiredXPathContext(){
+	return context;
+    }
 }




More information about the MOBY-guts mailing list