[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Fri Sep 3 20:28:16 UTC 2004
gordonp
Fri Sep 3 16:28:16 EDT 2004
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory pub.open-bio.org:/tmp/cvs-serv10407/src/main/org/biomoby/shared
Modified Files:
MobyDataServiceAssocInstance.java MobyDataSimpleInstance.java
Added Files:
MobyDataFloat.java MobyDataInt.java MobyDataString.java
Log Message:
Changes to introduction base data object instance classes (i.e. creating MOBY query data from Java objects, not handcrafted XML)
moby-live/Java/src/main/org/biomoby/shared MobyDataFloat.java,NONE,1.1 MobyDataInt.java,NONE,1.1 MobyDataString.java,NONE,1.1 MobyDataServiceAssocInstance.java,1.1,1.2 MobyDataSimpleInstance.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataServiceAssocInstance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataServiceAssocInstance.java 2004/04/21 17:26:46 1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataServiceAssocInstance.java 2004/09/03 20:28:16 1.2
@@ -3,30 +3,92 @@
import org.w3c.dom.Element;
/**
- * A convenience class that just associates a set of possible services to run with a data instance
+ * A convenience class that just associates a set of possible services to run with a data instance.
*/
public class MobyDataServiceAssocInstance extends MobyDataSimpleInstance{
+ protected MobyDataSimpleInstance dataInstance;
protected MobyService[] mobyServices;
- public MobyDataServiceAssocInstance(MobyDataType type, String name, String value, MobyService[] services){
- super(type, name, value);
+ public MobyDataServiceAssocInstance(MobyDataType type, String name, String id, MobyService[] services){
+ super(type, name, id);
mobyServices = services;
+ dataInstance = this;
}
public MobyDataServiceAssocInstance(Central central, Element simple, MobyService[] services) throws MobyException{
super(central, simple);
mobyServices = services;
+ dataInstance = this;
}
public MobyDataServiceAssocInstance(MobyDataSimpleInstance mdsi, MobyService[] services){
- super(mdsi.getDataType(), mdsi.getName(), mdsi.getId());
- setValue(mdsi.getValue());
+ super(mdsi.getName());
+ dataInstance = (MobyDataSimpleInstance) mdsi.clone();
mobyServices = services;
}
+ public Object clone(){
+ if(dataInstance == this){
+ // Avoid recursion, we're using the simple instance base behaviours
+ return super.clone();
+ }
+ else{
+ // Clone according to the base instance's subclass specific methods
+ return new MobyDataServiceAssocInstance(dataInstance, mobyServices);
+ }
+ }
+
public MobyService[] getServices(){
return mobyServices;
}
+
+ public MobyDataType getDataType(){
+ return dataInstance.getDataType();
+ }
+
+ public void setServices(MobyService[] services){
+ mobyServices = services;
+ }
+
+ public void setXmlMode(int mode) throws IllegalArgumentException{
+ dataInstance.setXmlMode(mode);
+ }
+
+ public String getValue(){
+ return dataInstance.getValue();
+ }
+
+ public void setId(String value){
+ dataInstance.setId(value);
+ }
+
+ public String getId(){
+ return dataInstance.getId();
+ }
+
+ public void addNamespace(MobyNamespace ns){
+ dataInstance.addNamespace(ns);
+ }
+
+ public MobyNamespace[] getNamespaces(){
+ return dataInstance.getNamespaces();
+ }
+
+ public void setValue(Element simple) throws javax.xml.transform.TransformerException{
+ dataInstance.setValue(simple);
+ }
+
+ public void setValue(String value){
+ dataInstance.setValue(value);
+ }
+
+ public String toString(){
+ return dataInstance.toString();
+ }
+
+ public String toXML(){
+ return dataInstance.toXML();
+ }
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java 2004/04/21 17:26:46 1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataSimpleInstance.java 2004/09/03 20:28:16 1.2
@@ -24,7 +24,7 @@
* SERVICE_XML_MODE.
*/
-public class MobyDataSimpleInstance extends MobyPrimaryDataSimple implements MobyDataInstance{
+public class MobyDataSimpleInstance extends MobyPrimaryDataSimple implements MobyDataInstance, Cloneable{
public static final int CENTRAL_XML_MODE = 124;
public static final int SERVICE_XML_MODE = 891;
protected int xmlMode = SERVICE_XML_MODE;
@@ -36,10 +36,10 @@
* If you're looking to pass in an XML string for the constructor, you can't. You can use
* the one argument constructor or this one, then use setValue(String).
*/
- public MobyDataSimpleInstance(MobyDataType dataType, String name, String value){
+ public MobyDataSimpleInstance(MobyDataType dataType, String name, String id){
super(name);
setDataType(dataType);
- setId(value);
+ setId(id);
}
/**
@@ -51,11 +51,27 @@
}
/**
+ * Creates a simple object from the input instance, as opposed to clone, which creates
+ * an exact copy.
+ */
+ public MobyDataSimpleInstance(MobyDataSimpleInstance mdsi){
+ super(mdsi.getName());
+ }
+
+ /**
* Standard constructor, build the object value using a DOM element.
* @throws MobyException if the XML passed in does not have a moby:Simple root node
*/
public MobyDataSimpleInstance(Central mobyCentral, Element simple) throws MobyException{
super(MobyPrefixResolver.getAttr(simple, "articleName"));
+
+ if(!simple.getLocalName().equals("Simple") || !(simple.getNamespaceURI() == null ||
+ simple.getNamespaceURI().length() == 0 ||
+ simple.getNamespaceURI().equals(MobyPrefixResolver.MOBY_XML_NAMESPACE))){
+ throw new MobyException("Element passed to MobyDataSimpleInstance was not a moby:Simple, but " +
+ simple.getNodeName());
+ }
+
NodeList children = simple.getElementsByTagName("*");
if(children == null || children.getLength() == 0){
throw new MobyException("Simple element (" + simple +
@@ -172,6 +188,26 @@
public String toString(){
return dataValue;
}
+
+ /**
+ * Simply calls new constructor with object's existing data type, name and value.
+ * Subclasses should override this method if more datafields need to be copied for
+ * an accurate clone of the Moby Data Instance (i.e. anything but a base object). The
+ * subclasses should ensure that they also return a MobyDataSimpleInstance
+ *
+ * @return an object of class MobyDataSimpleInstance
+ */
+ public Object clone(){
+ MobyDataSimpleInstance copy = null;
+ copy = new MobyDataSimpleInstance(getName());
+ copy.setDataType(getDataType());
+ copy.setNamespaces(getNamespaces());
+ copy.setId(getId());
+ if(!isObject){ // Complex object that has its own XML representation we'll just copy over
+ copy.setValue(getValue());
+ }
+ return copy;
+ }
/**
* Produces a full-blown XML fragment that depending on the value of getXmlMode() is either
More information about the MOBY-guts
mailing list