[MOBY-guts] biomoby commit
Paul Gordon
gordonp at dev.open-bio.org
Thu Jun 7 23:58:16 UTC 2007
gordonp
Thu Jun 7 19:58:15 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data
In directory dev.open-bio.org:/tmp/cvs-serv25503/src/main/org/biomoby/shared/data
Modified Files:
MobyContentInstance.java MobyDataBoolean.java
MobyDataBytes.java MobyDataComposite.java
MobyDataDateTime.java MobyDataFloat.java MobyDataInt.java
MobyDataObject.java MobyDataObjectSet.java MobyDataString.java
MobyDataUtils.java
Log Message:
Updates to deal with fact that more than one registry can be used as the source of type information
moby-live/Java/src/main/org/biomoby/shared/data MobyContentInstance.java,1.11,1.12 MobyDataBoolean.java,1.3,1.4 MobyDataBytes.java,1.6,1.7 MobyDataComposite.java,1.14,1.15 MobyDataDateTime.java,1.8,1.9 MobyDataFloat.java,1.6,1.7 MobyDataInt.java,1.5,1.6 MobyDataObject.java,1.15,1.16 MobyDataObjectSet.java,1.7,1.8 MobyDataString.java,1.5,1.6 MobyDataUtils.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyContentInstance.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/MobyContentInstance.java 2007/05/30 17:44:19 1.11
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyContentInstance.java 2007/06/07 23:58:15 1.12
@@ -1,5 +1,6 @@
package org.biomoby.shared.data;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.*;
import org.biomoby.shared.parser.MobyTags;
import org.biomoby.shared.parser.ServiceException;
@@ -80,6 +81,10 @@
* interface methods, with queryID as key, and MobyDataInstance Vectors (mobyData) as values.
*/
public MobyContentInstance(Element objectTag) throws MobyException{
+ this(objectTag, null);
+ }
+
+ public MobyContentInstance(Element objectTag, Registry registry) throws MobyException{
this();
if(!MobyTags.MOBYCONTENT.equals(objectTag.getLocalName())){
throw new MobyException("The content element provided (" +
@@ -122,7 +127,7 @@
System.err.println("Warning: found null element in DOM results (very strange)");
continue;
}
- parseDataGroup(dataGroup);
+ parseDataGroup(dataGroup, registry);
}
// If we got to this stage, we're okay in the sytax department.
@@ -185,7 +190,7 @@
debugPS = ps;
}
- public void parseDataGroup(Element dataGroupTag) throws MobyException{
+ public void parseDataGroup(Element dataGroupTag, Registry registry) throws MobyException{
String groupID = null;
MobyDataJob job = new MobyDataJob();
@@ -213,7 +218,7 @@
" collections in response " + groupID);
}
Element collectionTag = (Element) collections.item(j);
- MobyDataObjectSet collection = (MobyDataObjectSet) (MobyDataObject.createInstanceFromDOM(collectionTag));
+ MobyDataObjectSet collection = (MobyDataObjectSet) (MobyDataObject.createInstanceFromDOM(collectionTag, registry));
// Add completed collection to the output list
job.put(collection.getName(), collection);
@@ -237,11 +242,11 @@
throw new MobyException("Illegal XML: there is more than one tag in the response " +
groupID + " with the articleName " + name);
}
- job.put(name, MobyDataObject.createInstanceFromDOM((Element) simples.item(j)));
+ job.put(name, MobyDataObject.createInstanceFromDOM((Element) simples.item(j), registry));
}
// No anonymous data member yet
else if(!job.containsKey("")){
- job.put("", MobyDataObject.createInstanceFromDOM((Element) simples.item(j)));
+ job.put("", MobyDataObject.createInstanceFromDOM((Element) simples.item(j), registry));
}
else{
debugPS.println("More than one anonymous member, ignoring simple #" + j);
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataBoolean.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/MobyDataBoolean.java 2006/07/07 04:12:40 1.3
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataBoolean.java 2007/06/07 23:58:15 1.4
@@ -1,7 +1,10 @@
package org.biomoby.shared.data;
+
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.parser.MobyTags;
/**
* A class representing a MOBY Boolean primitive.
@@ -21,7 +24,11 @@
* @throws IllegalArgumentException if the element is not a String tag
*/
public MobyDataBoolean(org.w3c.dom.Element element) throws IllegalArgumentException{
- this(getName(element), getTextContents(element));
+ this(element, null);
+ }
+
+ public MobyDataBoolean(org.w3c.dom.Element element, Registry registry) throws IllegalArgumentException{
+ this(getName(element), getTextContents(element), registry);
setId(getId(element));
addNamespace(getNamespace(element));
}
@@ -31,13 +38,22 @@
* (i.e. String, StringBuffer, CharBuffer or StringBuilder).
*/
public MobyDataBoolean(String articleName, Boolean b){
+ this(articleName, b, null);
+ }
+
+ /** Every c-tor eventually winds up here */
+ public MobyDataBoolean(String articleName, Boolean b, Registry registry){
super(articleName);
- setDataType(MobyDataType.getDataType("Boolean"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYBOOLEAN, registry));
value = b;
}
public MobyDataBoolean(String articleName, boolean b){
- this(articleName, Boolean.valueOf(b));
+ this(articleName, Boolean.valueOf(b), null);
+ }
+
+ public MobyDataBoolean(String articleName, boolean b, Registry registry){
+ this(articleName, Boolean.valueOf(b), registry);
}
/**
@@ -46,21 +62,37 @@
* "Yes" and "1" are not acceptable.
*/
public MobyDataBoolean(String articleName, String booleanString){
- this(articleName, Boolean.valueOf(booleanString));
+ this(articleName, Boolean.valueOf(booleanString), null);
+ }
+
+ public MobyDataBoolean(String articleName, String booleanString, Registry registry){
+ this(articleName, Boolean.valueOf(booleanString), registry);
}
public MobyDataBoolean(Boolean b){
this("", b);
}
+ public MobyDataBoolean(Boolean b, Registry r){
+ this("", b, r);
+ }
+
public MobyDataBoolean(boolean b){
this("", b);
}
+ public MobyDataBoolean(boolean b, Registry r){
+ this("", b, r);
+ }
+
public MobyDataBoolean(String booleanString){
this("", booleanString);
}
+ public MobyDataBoolean(String booleanString, Registry r){
+ this("", booleanString, r);
+ }
+
public String toString(){
return value.toString();
}
@@ -117,7 +149,7 @@
public String toXML(){
MobyNamespace[] ns = getNamespaces();
if(xmlMode == MobyDataInstance.SERVICE_XML_MODE){
- return "<Boolean "+ getAttrXML() + ">" + value + "</Boolean>";
+ return "<"+MobyTags.MOBYBOOLEAN+" "+ getAttrXML() + ">" + value + "</"+MobyTags.MOBYBOOLEAN+">";
}
// Central mode, use default toXML provided by superclasses
else{
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataBytes.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataBytes.java 2007/04/13 01:55:36 1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataBytes.java 2007/06/07 23:58:15 1.7
@@ -1,6 +1,7 @@
package org.biomoby.shared.data;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyException;
import java.io.*;
@@ -34,12 +35,16 @@
* @throws IllegalArgumentException if the element is not a text-base64 tag, or doesn't inherit from it
*/
public MobyDataBytes(org.w3c.dom.Element element) throws MobyException{
- super(MobyDataType.getDataType(BASE64_DATATYPE), getName(element));
+ this(element, null);
+ }
+
+ public MobyDataBytes(org.w3c.dom.Element element, Registry registry) throws MobyException{
+ super(MobyDataType.getDataType(BASE64_DATATYPE, registry), getName(element));
setId(getId(element));
addNamespace(getNamespace(element));
- MobyDataType inputDataType = MobyDataType.getDataType(element.getLocalName());
- if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE))){
+ MobyDataType inputDataType = MobyDataType.getDataType(element.getLocalName(), registry);
+ if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE, registry))){
throw new MobyException("The given tag ("+ element.getLocalName() +
") does not inherit from " + BASE64_DATATYPE +
" in the MOBY Object Class Ontology, cannot " +
@@ -49,7 +54,7 @@
// Now, we know we have one field that represents the bytes,
// and there may be others which we will treat as regular composite members
- populateMembersFromDOM(element);
+ populateMembersFromDOM(element, registry);
MobyDataObject contents = get(ENCODED_MEMBER_NAME);
if(contents == null){
@@ -73,7 +78,11 @@
* @throws MobyException if the data provided is null, or could not be encoded(?!)
*/
public MobyDataBytes(String name, byte[] data) throws MobyException{
- super(MobyDataType.getDataType(BASE64_DATATYPE), name);
+ this(name, data, (Registry) null);
+ }
+
+ public MobyDataBytes(String name, byte[] data, Registry registry) throws MobyException{
+ super(MobyDataType.getDataType(BASE64_DATATYPE, registry), name);
storeBytes(data);
}
@@ -82,7 +91,7 @@
*/
public MobyDataBytes(String name, byte[] data, MobyDataType inputDataType) throws MobyException{
this(name, data);
- if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE))){
+ if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE, inputDataType.getRegistry()))){
throw new MobyException("The given data type ("+ inputDataType.getName() +
") does not inherit from " + BASE64_DATATYPE +
" in the MOBY Object Class Ontology, cannot " +
@@ -97,10 +106,14 @@
* Currently Base64 encoding is acceptable, UU Decoding has yet to be implemented..
*/
public MobyDataBytes(String name, CharSequence data){
- super(MobyDataType.getDataType(BASE64_DATATYPE), name);
- setDataType(MobyDataType.getDataType(BASE64_DATATYPE));
+ this(name, data, (Registry) null);
+ }
+
+ public MobyDataBytes(String name, CharSequence data, Registry registry){
+ super(MobyDataType.getDataType(BASE64_DATATYPE, registry), name);
+ setDataType(MobyDataType.getDataType(BASE64_DATATYPE, registry));
// TODO: add check that the data is valid Base64 format!
- put(ENCODED_MEMBER_NAME, new MobyDataString(ENCODED_MEMBER_NAME, data));
+ put(ENCODED_MEMBER_NAME, new MobyDataString(ENCODED_MEMBER_NAME, data, registry));
}
/**
@@ -110,7 +123,7 @@
*/
public MobyDataBytes(String name, CharSequence data, MobyDataType inputDataType) throws MobyException{
this(name, data);
- if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE))){
+ if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE, inputDataType.getRegistry()))){
throw new MobyException("The given data type ("+ inputDataType.getName() +
") does not inherit from " + BASE64_DATATYPE +
" in the MOBY Object Class Ontology, cannot " +
@@ -125,7 +138,11 @@
* @param resourceURL the URL of the resource to encode, such as "file:..." or "http:..."
*/
public MobyDataBytes(String name, java.net.URL resourceURL) throws MobyException, IOException{
- super(MobyDataType.getDataType(BASE64_DATATYPE), name);
+ this(name, resourceURL, (Registry) null);
+ }
+
+ public MobyDataBytes(String name, java.net.URL resourceURL, Registry registry) throws MobyException, IOException{
+ super(MobyDataType.getDataType(BASE64_DATATYPE, registry), name);
if(resourceURL == null){
return;
}
@@ -151,7 +168,7 @@
*/
public MobyDataBytes(String name, java.net.URL resourceURL, MobyDataType inputDataType) throws IOException, MobyException{
this(name, resourceURL);
- if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE))){
+ if(!inputDataType.inheritsFrom(MobyDataType.getDataType(BASE64_DATATYPE, inputDataType.getRegistry()))){
throw new MobyException("The given data type ("+ inputDataType.getName() +
") does not inherit from " + BASE64_DATATYPE +
" in the MOBY Object Class Ontology, cannot " +
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java 2007/04/13 01:56:12 1.14
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataComposite.java 2007/06/07 23:58:15 1.15
@@ -9,12 +9,8 @@
import java.util.Set;
import java.util.Vector;
-import org.biomoby.shared.Central;
-import org.biomoby.shared.MobyDataType;
-import org.biomoby.shared.MobyException;
-import org.biomoby.shared.MobyNamespace;
-import org.biomoby.shared.MobyPrefixResolver;
-import org.biomoby.shared.MobyRelationship;
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.*;
import org.biomoby.shared.parser.MobyTags;
/**
@@ -32,12 +28,19 @@
* @throws MobyException if the element is not a MobyObject tag
*/
public MobyDataComposite(org.w3c.dom.Element element) throws MobyException{
- this(MobyDataType.getDataType(element.getLocalName()), getName(element), getNamespace(element), getId(element));
+ this(element, null);
+ }
+
+ public MobyDataComposite(org.w3c.dom.Element element, Registry registry) throws MobyException{
+ this(MobyDataType.getDataType(element.getLocalName(), registry),
+ getName(element),
+ getNamespace(element),
+ getId(element));
- populateMembersFromDOM(element);
+ populateMembersFromDOM(element, registry);
}
- protected void populateMembersFromDOM(org.w3c.dom.Element element) throws MobyException{
+ protected void populateMembersFromDOM(org.w3c.dom.Element element, Registry registry) throws MobyException{
// Decompose the children
org.w3c.dom.NodeList substructures = MobyPrefixResolver.getChildElements(element, "*"); //wildcard
int numSubstructures = substructures.getLength();
@@ -87,9 +90,13 @@
* ontology, otherwise the datatype will be null.
*/
public MobyDataComposite(String typeName, String name, String namespace, String id){
+ this(typeName, name, namespace, id, (Registry) null);
+ }
+
+ public MobyDataComposite(String typeName, String name, String namespace, String id, Registry registry){
super(namespace, id);
setName(name);
- setDataType(MobyDataType.getDataType(typeName));
+ setDataType(MobyDataType.getDataType(typeName, registry));
members = new ConcurrentHashMap<String, MobyDataObject>();
}
@@ -111,7 +118,7 @@
setDataType(type);
members = new ConcurrentHashMap<String, MobyDataObject>();
- MobyDataType dt = MobyDataType.getDataType(type.getName());
+ MobyDataType dt = MobyDataType.getDataType(type.getName(), type.getRegistry());
MobyRelationship[] children = dt.getAllChildren();
// If one arg, resolve it's name, set it, and we're done
@@ -201,7 +208,11 @@
}
public MobyDataComposite(String typeName, String name){
- this(MobyDataType.getDataType(typeName), name);
+ this(typeName, name, (Registry) null);
+ }
+
+ public MobyDataComposite(String typeName, String name, Registry r){
+ this(MobyDataType.getDataType(typeName, r), name);
}
public MobyDataComposite(MobyDataType type){
@@ -209,7 +220,11 @@
}
public MobyDataComposite(String typeName){
- this(MobyDataType.getDataType(typeName));
+ this(typeName, (Registry) null);
+ }
+
+ public MobyDataComposite(String typeName, Registry r){
+ this(MobyDataType.getDataType(typeName, r));
}
public Object clone(){
@@ -394,7 +409,7 @@
MobyRelationship relationship = getDataType().getChild(fieldName);
if(relationship == null){
- relationship = MobyDataType.getDataType(getDataType().getName()).getChild(fieldName);
+ relationship = MobyDataType.getDataType(getDataType().getName(), getDataType().getRegistry()).getChild(fieldName);
if(relationship == null){
String memberNames = "";
for(MobyRelationship rel: getDataType().getChildren()){
@@ -405,7 +420,7 @@
getDataType().getName() + ", valid member names are:" + memberNames);
}
}
- MobyDataType childDataType = MobyDataType.getDataType(relationship.getDataTypeName());
+ MobyDataType childDataType = MobyDataType.getDataType(relationship.getDataTypeName(), getDataType().getRegistry());
if(!value.getDataType().inheritsFrom(childDataType)){
// Incompatible types
throw new IllegalArgumentException("The member '" + fieldName + "' for object '"+ getName() +
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataDateTime.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/MobyDataDateTime.java 2007/05/29 23:49:32 1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataDateTime.java 2007/06/07 23:58:15 1.9
@@ -1,13 +1,12 @@
-
package org.biomoby.shared.data;
+
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.parser.MobyTags;
+
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.TimeZone;
+import java.util.*;
/**
* A class representing a MOBY DateTime, which is a primitive in MOBY.
@@ -36,7 +35,11 @@
* @throws IllegalArgumentException if the element is not a DateTime tag, or the text children of the element do not encode a valid ISO8601 date/time
*/
public MobyDataDateTime(org.w3c.dom.Element element) throws IllegalArgumentException{
- this(getName(element), getTextContents(element));
+ this(element, null);
+ }
+
+ public MobyDataDateTime(org.w3c.dom.Element element, Registry registry) throws IllegalArgumentException{
+ this(getName(element), getTextContents(element), registry);
setId(getId(element));
addNamespace(getNamespace(element));
}
@@ -46,8 +49,12 @@
* @param stringISO8601 if null, the current local date and time is used
*/
public MobyDataDateTime(String articleName, String stringISO8601) throws IllegalArgumentException{
+ this(articleName, stringISO8601, null);
+ }
+
+ public MobyDataDateTime(String articleName, String stringISO8601, Registry registry) throws IllegalArgumentException{
super(articleName);
- setDataType(MobyDataType.getDataType("DateTime"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYDATETIME, registry));
value = parseISO8601(stringISO8601);
}
@@ -56,8 +63,12 @@
}
public MobyDataDateTime(String articleName, GregorianCalendar cal){
+ this(articleName, cal, (Registry) null);
+ }
+
+ public MobyDataDateTime(String articleName, GregorianCalendar cal, Registry registry){
super(articleName, "");
- setDataType(MobyDataType.getDataType("DateTime"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYDATETIME, registry));
value = cal;
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataFloat.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataFloat.java 2006/07/07 04:12:40 1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataFloat.java 2007/06/07 23:58:15 1.7
@@ -3,8 +3,10 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.parser.MobyTags;
/**
* A class representing a MOBY Float primitive. Note that the
@@ -26,7 +28,11 @@
* @throws IllegalArgumentException if the element is not a Float tag
*/
public MobyDataFloat(org.w3c.dom.Element element) throws IllegalArgumentException{
- this(getName(element), getTextContents(element));
+ this(element, null);
+ }
+
+ public MobyDataFloat(org.w3c.dom.Element element, Registry registry) throws IllegalArgumentException{
+ this(getName(element), getTextContents(element), registry);
setId(getId(element));
addNamespace(getNamespace(element));
}
@@ -36,8 +42,12 @@
* Float, Double, Integer, BigDecimal, etc.
*/
public MobyDataFloat(String articleName, Number n){
+ this(articleName, n, null);
+ }
+
+ public MobyDataFloat(String articleName, Number n, Registry r){
super(articleName);
- setDataType(MobyDataType.getDataType("Float"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYFLOAT, r));
if(n instanceof BigDecimal){
value = (BigDecimal) n;
}
@@ -49,8 +59,12 @@
}
}
+ public MobyDataFloat(Number n, Registry r){
+ this("", n, r);
+ }
+
public MobyDataFloat(Number n){
- this("", n);
+ this("", n, null);
}
/**
@@ -58,13 +72,21 @@
* If you want to pass in a float or int, cast it to a double.
*/
public MobyDataFloat(String articleName, double d){
+ this(articleName, d, null);
+ }
+
+ public MobyDataFloat(String articleName, double d, Registry registry){
super(articleName);
- setDataType(MobyDataType.getDataType("Float"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYFLOAT, registry));
value = new BigDecimal(d);
}
+ public MobyDataFloat(double d, Registry r){
+ this("", d, r);
+ }
+
public MobyDataFloat(double d){
- this("", d);
+ this("", d, null);
}
/**
@@ -74,13 +96,21 @@
* @throws NumberFormatException if the string does not represent a number
*/
public MobyDataFloat(String articleName, String stringNumber) throws NumberFormatException{
+ this(articleName, stringNumber, null);
+ }
+
+ public MobyDataFloat(String articleName, String stringNumber, Registry registry) throws NumberFormatException{
super(articleName);
- setDataType(MobyDataType.getDataType("Float"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYFLOAT, registry));
value = new BigDecimal(stringNumber);
}
public MobyDataFloat(String stringNumber){
- this("", stringNumber);
+ this("", stringNumber, null);
+ }
+
+ public MobyDataFloat(String stringNumber, Registry registry){
+ this("", stringNumber, registry);
}
public Object clone(){
@@ -315,7 +345,8 @@
public String toXML(){
MobyNamespace[] ns = getNamespaces();
if(xmlMode == MobyDataInstance.SERVICE_XML_MODE){
- return "<Float " + getAttrXML() + ">" + value.toString() + "</Float>";
+ return "<" + MobyTags.MOBYFLOAT + " " + getAttrXML() + ">" +
+ value.toString() + "</" + MobyTags.MOBYFLOAT + ">";
}
else{
return super.toXML();
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataInt.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/MobyDataInt.java 2006/07/07 04:12:40 1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataInt.java 2007/06/07 23:58:15 1.6
@@ -1,7 +1,8 @@
-
package org.biomoby.shared.data;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
+import org.biomoby.shared.parser.MobyTags;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -26,7 +27,11 @@
* @throws IllegalArgumentException if the element is not a Integer tag
*/
public MobyDataInt(org.w3c.dom.Element element) throws IllegalArgumentException{
- this(getName(element), getTextContents(element));
+ this(element, null);
+ }
+
+ public MobyDataInt(org.w3c.dom.Element element, Registry registry) throws IllegalArgumentException{
+ this(getName(element), getTextContents(element), registry);
setId(getId(element));
addNamespace(getNamespace(element));
}
@@ -37,8 +42,12 @@
* Real numbers will be converted to their integer equivalents.
*/
public MobyDataInt(String articleName, Number n){
+ this(articleName, n, null);
+ }
+
+ public MobyDataInt(String articleName, Number n, Registry registry){
super(articleName);
- setDataType(MobyDataType.getDataType("Integer"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYINTEGER, registry));
if(n instanceof BigInteger){
value = (BigInteger) n;
}
@@ -51,7 +60,11 @@
}
public MobyDataInt(Number n){
- this("", n);
+ this("", n, null);
+ }
+
+ public MobyDataInt(Number n, Registry r){
+ this("", n, r);
}
/**
@@ -59,8 +72,12 @@
* If you want to pass in a float or double, cast it to an int.
*/
public MobyDataInt(String articleName, int i){
+ this(articleName, i, null);
+ }
+
+ public MobyDataInt(String articleName, int i, Registry registry){
super(articleName);
- setDataType(MobyDataType.getDataType("Integer"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYINTEGER, registry));
value = new BigInteger(""+i);
}
@@ -74,8 +91,12 @@
* @throws NumberFormatException if the string does not represent an integer number
*/
public MobyDataInt(String articleName, String stringNumber) throws NumberFormatException{
+ this(articleName, stringNumber, null);
+ }
+
+ public MobyDataInt(String articleName, String stringNumber, Registry registry) throws NumberFormatException{
super(articleName);
- setDataType(MobyDataType.getDataType("Integer"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYINTEGER, registry));
value = new BigInteger(stringNumber);
}
@@ -273,7 +294,8 @@
public String toXML(){
if(xmlMode == MobyDataInstance.SERVICE_XML_MODE){
- return "<Integer " + getAttrXML() + ">" + value.toString() + "</Integer>";
+ return "<" + MobyTags.MOBYINTEGER + " " + getAttrXML() + ">" +
+ value.toString() + "</" + MobyTags.MOBYINTEGER + ">";
}
else{
return super.toXML();
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java 2007/04/27 13:45:29 1.15
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObject.java 2007/06/07 23:58:15 1.16
@@ -16,6 +16,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.*;
import org.biomoby.shared.parser.MobyTags;
@@ -44,7 +45,11 @@
* @throws MobyException if the element is not an Object tag, or is missing a required attribute
*/
public MobyDataObject(Element element) throws MobyException{
- this(getNamespace(element).getName(), getId(element));
+ this(element, null);
+ }
+
+ public MobyDataObject(Element element, Registry registry) throws MobyException{
+ this(getNamespace(element).getName(), getId(element), registry);
setName(getName(element));
}
@@ -53,16 +58,24 @@
* Instance information can be filled out later with setId() and setNamespace().
*/
public MobyDataObject(String name){
+ this(name, (Registry) null);
+ }
+
+ public MobyDataObject(String name, Registry registry){
super(name);
- setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT, registry));
}
/**
* Constructor convenient for a base object with a namespace and ID.
*/
public MobyDataObject(String namespace, String id){
+ this(namespace, id, null);
+ }
+
+ public MobyDataObject(String namespace, String id, Registry registry){
super("");
- setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYOBJECT, registry));
setId(id);
MobyNamespace nsObj = MobyNamespace.getNamespace(namespace);
@@ -91,30 +104,34 @@
* @throws MobyException if the requested datatype is not a primtive, or the value could not be used for that data type (e.g an integer out of the string "Bar")
*/
public static MobyDataObject createInstanceFromString(String typeName, String value) throws MobyException{
+ return createInstanceFromString(typeName, value, null);
+ }
+
+ public static MobyDataObject createInstanceFromString(String typeName, String value, Registry registry) throws MobyException{
if(typeName == null){
return null;
}
if(MobyTags.MOBYOBJECT.equals(typeName)){
- return new MobyDataObject("", value);
+ return new MobyDataObject("", value, registry);
}
else if(MobyTags.MOBYINTEGER.equals(typeName)){
- return new MobyDataInt("", value);
+ return new MobyDataInt("", value, registry);
}
else if(MobyTags.MOBYFLOAT.equals(typeName)){
- return new MobyDataFloat("", value);
+ return new MobyDataFloat("", value, registry);
}
else if(MobyTags.MOBYSTRING.equals(typeName)){
- return new MobyDataString("", value);
+ return new MobyDataString("", value, registry);
}
else if(MobyTags.MOBYBOOLEAN.equals(typeName)){
- return new MobyDataBoolean("", value);
+ return new MobyDataBoolean("", value, registry);
}
else if(MobyTags.MOBYDATETIME.equals(typeName)){
- return new MobyDataDateTime("", value);
+ return new MobyDataDateTime("", value, registry);
}
else{
- MobyDataType type = MobyDataType.getDataType(typeName);
+ MobyDataType type = MobyDataType.getDataType(typeName, registry);
if(type != null && type.inheritsFrom(MobyDataBytes.BASE64_DATATYPE)){
return new MobyDataBytes("", value, type);
}
@@ -134,6 +151,10 @@
* @param objectTag the W3C DOM Element node corresponding to the object's enclosing tag, or a Simple tag
*/
public static MobyDataInstance createInstanceFromDOM(Element objectTag) throws MobyException{
+ return createInstanceFromDOM(objectTag, null);
+ }
+
+ public static MobyDataInstance createInstanceFromDOM(Element objectTag, Registry registry) throws MobyException{
MobyDataObject object = null;
if(objectTag == null){
@@ -156,38 +177,38 @@
// There are six types of objects we can populate with data directly
// plus Collections and Secondary Parameters. Otherwise it is a composite.
else if(MobyTags.MOBYOBJECT.equals(objectClass)){
- return new MobyDataObject(objectTag);
+ return new MobyDataObject(objectTag, registry);
}
else if(MobyTags.MOBYINTEGER.equals(objectClass)){
- return new MobyDataInt(objectTag);
+ return new MobyDataInt(objectTag, registry);
}
else if(MobyTags.MOBYFLOAT.equals(objectClass)){
- return new MobyDataFloat(objectTag);
+ return new MobyDataFloat(objectTag, registry);
}
else if(MobyTags.MOBYSTRING.equals(objectClass)){
- return new MobyDataString(objectTag);
+ return new MobyDataString(objectTag, registry);
}
else if(MobyTags.MOBYBOOLEAN.equals(objectClass)){
- return new MobyDataBoolean(objectTag);
+ return new MobyDataBoolean(objectTag, registry);
}
else if(MobyTags.MOBYDATETIME.equals(objectClass)){
- return new MobyDataDateTime(objectTag);
+ return new MobyDataDateTime(objectTag, registry);
}
else if(MobyTags.COLLECTION.equals(objectClass)){
- return new MobyDataObjectSet(objectTag);
+ return new MobyDataObjectSet(objectTag, registry);
}
else if(MobyDataSecondaryInstance.ELEMENT_NAME.equals(objectClass)){
return new MobyDataSecondaryInstance(objectTag);
}
// Must otherwise be a composite
else{
- MobyDataType type = MobyDataType.getDataType(objectClass);
+ MobyDataType type = MobyDataType.getDataType(objectClass, registry);
// Treat base64-encoded binary data as a special case, as we have a convenience class for it
if(type != null && type.inheritsFrom(MobyDataType.getDataType(MobyDataBytes.BASE64_DATATYPE))){
- return new MobyDataBytes(objectTag);
+ return new MobyDataBytes(objectTag, registry);
}
else{
- return new MobyDataComposite(objectTag);
+ return new MobyDataComposite(objectTag, registry);
}
}
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java 2007/04/26 15:06:15 1.7
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataObjectSet.java 2007/06/07 23:58:15 1.8
@@ -1,19 +1,10 @@
package org.biomoby.shared.data;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Vector;
-
-import org.biomoby.shared.MobyDataType;
-import org.biomoby.shared.MobyException;
-import org.biomoby.shared.MobyNamespace;
-import org.biomoby.shared.MobyPrimaryData;
-import org.biomoby.shared.MobyPrimaryDataSet;
-import org.biomoby.shared.MobyPrimaryDataSimple;
-import org.biomoby.shared.MobyPrefixResolver;
+import java.util.*;
+
+import org.biomoby.registry.meta.Registry;
+import org.biomoby.shared.*;
+import org.biomoby.shared.parser.MobyTags;
/**
* This class adds to MobyPrimaryDataSet the ability to get and set instantiated MOBY objects.
@@ -33,7 +24,11 @@
private int xmlMode = MobyDataInstance.CENTRAL_XML_MODE;
public MobyDataObjectSet(org.w3c.dom.Element e) throws MobyException{
- this(MobyDataObject.getName(e), getChildren(e));
+ this(e, null);
+ }
+
+ public MobyDataObjectSet(org.w3c.dom.Element e, Registry registry) throws MobyException{
+ this(MobyDataObject.getName(e), getChildren(e, registry));
if(getName() == null){
throw new MobyException("Anonymous collections are not allowed (need articleName), input was :\n" + e);
@@ -41,13 +36,13 @@
}
- public static Collection getChildren(org.w3c.dom.Element e) throws MobyException{
+ public static Collection getChildren(org.w3c.dom.Element e, Registry registry) throws MobyException{
Vector members = new Vector();
org.w3c.dom.NodeList children = MobyPrefixResolver.getChildElements(e, "*"); // wildcard
int numChildren = children.getLength();
for(int i = 0; i < numChildren; i++){
- members.add(MobyDataObject.createInstanceFromDOM((org.w3c.dom.Element) children.item(i)));
+ members.add(MobyDataObject.createInstanceFromDOM((org.w3c.dom.Element) children.item(i), registry));
}
return members;
}
@@ -516,39 +511,46 @@
StringBuffer collectionXml = new StringBuffer();
if(xmlMode == MobyDataInstance.SERVICE_XML_MODE){
- collectionXml.append("<moby:Collection xmlns:moby=\""+MobyPrefixResolver.MOBY_XML_NAMESPACE+
+ collectionXml.append("<moby:" + MobyTags.COLLECTION + " xmlns:moby=\""+MobyPrefixResolver.MOBY_XML_NAMESPACE+
(getName() != null ? "\" moby:articleName=\"" + getName() : "") +
"\">\n");
for(MobyDataObject mdsi: bag){
mdsi.setXmlMode(xmlMode);
- collectionXml.append("<Simple>"+mdsi.toXML()+"</Simple>");
+ collectionXml.append("<"+MobyTags.SIMPLE+">"+mdsi.toXML()+"</"+MobyTags.SIMPLE+">");
}
- collectionXml.append("\n</moby:Collection>\n");
+ collectionXml.append("\n</moby:" + MobyTags.COLLECTION + ">\n");
}
// Otherwise it's MOBY Central query mode
// We need to find out what object classes are present in the array, and
// enumerate them (the types, not the instances).
else{
- collectionXml.append("<Collection>\n");
- Hashtable printed = new Hashtable();
-
- for(MobyDataObject mdsi: bag){
- // Could the DataType be null? I hope not!
- String objectClass = mdsi.getDataType().getName();
+ collectionXml.append("<"+MobyTags.COLLECTION+">\n");
- // A new data type for the collection?
- if(!printed.containsKey(objectClass)){
- mdsi.setXmlMode(xmlMode);
+ MobyDataObject commonDataTemplate = new MobyDataObject("");
+ commonDataTemplate.setDataType(getDataType());
+ commonDataTemplate.setNamespaces(getNamespaces());
+ collectionXml.append(commonDataTemplate.toXML());
+
+ // Hashtable printed = new Hashtable();
+// for(MobyDataObject mdsi: bag){
+// // Could the DataType be null? I hope not!
+// String objectClass = mdsi.getDataType().getName();
+
+// // A new data type for the collection? Note to self (Paul), this doesn't seem right, should have one type only ...since the 0.86 spec
+// if(!printed.containsKey(objectClass)){
+// mdsi.setXmlMode(xmlMode);
- collectionXml.append(mdsi.toXML());
+// collectionXml.append(mdsi.toXML());
- printed.put(objectClass, "printed object type in MOBY central input collection");
- }
- }
- collectionXml.append("</Collection>\n");
+// printed.put(objectClass, "printed object type in MOBY central input collection");
+// }
+// }
+
+
+ collectionXml.append("</"+MobyTags.COLLECTION+">\n");
}
return collectionXml.toString();
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataString.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/MobyDataString.java 2006/07/07 04:12:40 1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataString.java 2007/06/07 23:58:15 1.6
@@ -1,7 +1,9 @@
-
package org.biomoby.shared.data;
+
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyNamespace;
+import org.biomoby.shared.parser.MobyTags;
/**
* A class representing a MOBY String primitive.
@@ -21,7 +23,11 @@
* @throws IllegalArgumentException if the element is not a String tag
*/
public MobyDataString(org.w3c.dom.Element element) throws IllegalArgumentException{
- this(getName(element), getTextContents(element));
+ this(element, null);
+ }
+
+ public MobyDataString(org.w3c.dom.Element element, Registry registry) throws IllegalArgumentException{
+ this(getName(element), getTextContents(element), registry);
setId(getId(element));
addNamespace(getNamespace(element));
}
@@ -31,13 +37,21 @@
* (i.e. String, StringBuffer, CharBuffer or StringBuilder).
*/
public MobyDataString(String articleName, CharSequence stringValue){
+ this(articleName, stringValue, null);
+ }
+
+ public MobyDataString(String articleName, CharSequence stringValue, Registry registry){
super(articleName);
- setDataType(MobyDataType.getDataType("String"));
+ setDataType(MobyDataType.getDataType(MobyTags.MOBYSTRING, registry));
value = new StringBuffer(stringValue.toString());
}
public MobyDataString(CharSequence stringValue){
- this("", stringValue);
+ this("", stringValue, null);
+ }
+
+ public MobyDataString(CharSequence stringValue, Registry registry){
+ this("", stringValue, registry);
}
public String toString(){
@@ -89,8 +103,9 @@
tmpValue = "";
}
- return "<String "+ getAttrXML() + " xml:space=\"preserve\">" + tmpValue + "</String>";
- }
+ return "<" + MobyTags.MOBYSTRING + " "+ getAttrXML() + " xml:space=\"preserve\">" +
+ tmpValue + "</" + MobyTags.MOBYSTRING + ">";
+ }
// Central mode, use default toXML provided by superclasses
else{
return super.toXML();
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataUtils.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataUtils.java 2007/03/29 19:40:52 1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/data/MobyDataUtils.java 2007/06/07 23:58:15 1.7
@@ -1,5 +1,6 @@
package org.biomoby.shared.data;
+import org.biomoby.registry.meta.Registry;
import org.biomoby.shared.parser.MobyTags;
import org.biomoby.shared.*;
import org.xml.sax.InputSource;
@@ -59,7 +60,11 @@
* Create a MOBY Java object representation from a MOBY XML payload stored in a String.
*/
public static MobyContentInstance fromXMLDocument(String xmlData) throws Exception{
- return fromXMLDocument(new StringReader(xmlData));
+ return fromXMLDocument(new StringReader(xmlData), null);
+ }
+
+ public static MobyContentInstance fromXMLDocument(String xmlData, Registry registry) throws Exception{
+ return fromXMLDocument(new StringReader(xmlData), registry);
}
/**
@@ -67,6 +72,10 @@
* (a byte stream that will becoverted by the parser into character data).
*/
public static MobyContentInstance fromXMLDocument(InputStream is) throws Exception{
+ return fromXMLDocument(is, null);
+ }
+
+ public static MobyContentInstance fromXMLDocument(InputStream is, Registry registry) throws Exception{
// Load an XML document
javax.xml.parsers.DocumentBuilder docBuilder = null;
try{
@@ -91,13 +100,17 @@
// Select a node from the document and see if any of the mappings
// work out, in which case we can check what services we can run
Element doc_root = domDoc.getDocumentElement();
- return fromXMLDocument(doc_root);
+ return fromXMLDocument(doc_root, registry);
}
/**
* Create a MOBY Java object representation from a MOBY XML payload at the given URL.
*/
public static MobyContentInstance fromXMLDocument(java.net.URL url) throws Exception{
+ return fromXMLDocument(url, null);
+ }
+
+ public static MobyContentInstance fromXMLDocument(java.net.URL url, Registry registry) throws Exception{
// Load an XML document
javax.xml.parsers.DocumentBuilder docBuilder = null;
try{
@@ -122,13 +135,17 @@
// Select a node from the document and see if any of the mappings
// work out, in which case we can check what services we can run
Element doc_root = domDoc.getDocumentElement();
- return fromXMLDocument(doc_root);
+ return fromXMLDocument(doc_root, registry);
}
/**
* Create a MOBY Java object representation from a MOBY XML payload coming from a Reader (character data).
*/
public static MobyContentInstance fromXMLDocument(Reader reader) throws Exception{
+ return fromXMLDocument(reader, null);
+ }
+
+ public static MobyContentInstance fromXMLDocument(Reader reader, Registry registry) throws Exception{
// Load an XML document
javax.xml.parsers.DocumentBuilder docBuilder = null;
try{
@@ -153,7 +170,7 @@
// Select a node from the document and see if any of the mappings
// work out, in which case we can check what services we can run
Element doc_root = domDoc.getDocumentElement();
- return fromXMLDocument(doc_root);
+ return fromXMLDocument(doc_root, registry);
}
@@ -163,6 +180,16 @@
* @param doc_root the document's base MOBY tag
*/
public static MobyContentInstance fromXMLDocument(Element doc_root) throws Exception{
+ return fromXMLDocument(doc_root, null);
+ }
+
+ /**
+ * Create a MOBY Java object representation from a MOBY XML payload represented in a DOM.
+ *
+ * @param doc_root the document's base MOBY tag
+ * @param registry the Mony Central from which to retrieve the data type definitions, uses default registry if null
+ */
+ public static MobyContentInstance fromXMLDocument(Element doc_root, Registry registry) throws Exception{
if(doc_root == null){
throw new MobyException("The passed in element was null");
}
@@ -204,7 +231,7 @@
MobyPrefixResolver.MOBY_XML_NAMESPACE);
}
- MobyContentInstance contents = new MobyContentInstance((Element) envelope.item(0));
+ MobyContentInstance contents = new MobyContentInstance((Element) envelope.item(0), registry);
return contents;
}
More information about the MOBY-guts
mailing list