Version: 1.1.1

org.biomoby.shared.data
Class MobyDataObject

java.lang.Object
  extended by org.biomoby.shared.MobyData
      extended by org.biomoby.shared.MobyPrimaryData
          extended by org.biomoby.shared.MobyPrimaryDataSimple
              extended by org.biomoby.shared.data.MobyDataObject
All Implemented Interfaces:
Cloneable, Comparable, MobyDataInstance
Direct Known Subclasses:
MobyDataBoolean, MobyDataComposite, MobyDataDateTime, MobyDataFloat, MobyDataInt, MobyDataObjectSAI, MobyDataObjectVector, MobyDataString

public class MobyDataObject
extends MobyPrimaryDataSimple
implements MobyDataInstance, Cloneable, Comparable

A class representing a base MOBY object (i.e. just a namespace and id) that has been instantiated. If you are looking to represent an object with members (e.g. DNASequence), look at MobyDataComposite. If you are looking to represent a MOBY primitive object, please see the appropriate subclass of this class (e.g. MobyDataInteger). This class provides methods to instantiate the object value either simply using an ID (in which case an Object tag is created automatically), or via XML input either from a DOM Element (preferred) or a string containing the XML. The toXML method will return either service call or search template formatted XML depending on the mode set. Having both modes is useful because the data instance created from a previous call can be passed to a service search template by switching the XML mode. By default the object is in MobyDataInstance.SERVICE_XML_MODE.

Author:
Paul Gordon (gordonp@ucalgary.ca)

Field Summary
 
Fields inherited from interface org.biomoby.shared.data.MobyDataInstance
CENTRAL_XML_MODE, SERVICE_XML_MODE
 
Constructor Summary
MobyDataObject(Element element)
          Construct the object using a DOM fragment.
MobyDataObject(Element element, Registry registry)
           
MobyDataObject(MobyDataObject mobj)
          Creates a base object with the same name, namespace and id as the input instance, as opposed to clone, which creates an exact copy of all the fields and the datatype.
MobyDataObject(String name)
          Constructor with no instance information, just a name (which can be blank).
MobyDataObject(String name, Registry registry)
           
MobyDataObject(String namespace, String id)
          Constructor convenient for a base object with a namespace and ID.
MobyDataObject(String namespace, String id, Registry registry)
           
 
Method Summary
 void addCrossReference(MobyDataObject mdsi)
           
 void addCrossReferences(Element e)
           
 void addCrossReferences(Element e, Registry reg)
           
 void addProvisionInfo(Element e)
           
 MobyDataObject clone()
          Simply calls new constructor with object's existing data type, name and value.
 int compareTo(Object o)
          This method lexically compares in the order of value, ID, name if passed in object is a MobyDataObject.
static MobyDataInstance createInstanceFromDOM(Element objectTag)
          This method creates a MobyDataObject of the appropriate subclass for a given input XML tree (e.g. base objects like MobyDataObject and MobyDataInt, or complex objects like MobyDataDateTime or MobyDataComposite, or even a MobyDataSecondaryInstance).
static MobyDataInstance createInstanceFromDOM(Element objectTag, Registry registry)
           
static MobyDataObject createInstanceFromString(String typeName, String value)
          Construct a primitive data type instance from a string value.
static MobyDataObject createInstanceFromString(String typeName, String value, Registry registry)
           
static MobyDataInstance createInstanceFromXML(String mobyXML)
          Similar to createObjectFromDOM(), but parses the XML for you using the JAXP parser discovery mechanism.
 boolean equals(Object passedInObject)
          Used to see if two objects are equivalent.
 Collection getCrossReferences()
          Call this method if you would like to modify the cross references, such as removing items, clearing the collection, etc.
static String getId(Element e)
           
static String getName(Element e)
          Determine the name of the element if an enclosing tag (e.g.
 Object getObject()
          Gives access to the Java object instance underlying the MobyData instance.
 MobyNamespace getPrimaryNamespace()
           
 MobyProvisionInfo getProvisionInfo()
           
static String getTextContents(Element element)
          Similar to DOM level 3 getTextContent, but only elements are excepted as input, and text inside children elements is not picked up.
 String getValue()
          A lexical (prefereably human readable) representation of the underlying object value (not including the namespace and ID).
 int getXmlMode()
          Report whether toXML will produce Central template or service call instance XML.
 boolean hasCrossReferences()
           
 void setId(String value)
          Used to set the data instance value based on an ID string. i.e. just an Object.
 void setName(String name)
          Please note that you almost never want to call this method in a client.
 void setPrimaryNamespace(MobyNamespace ns)
          This sets the namespace that will be used in toXML(), since in the XML representation for service execution, you can only have one namespace.
 void setProvisionInfo(MobyProvisionInfo info)
           
 void setXmlMode(int mode)
          Determined whether toXML will return a Central template value or a service call instance value.
 String toString()
          Convenience method to get the basic XML representation
 String toXML()
          Produces a full-blown XML fragment that depending on the value of getXmlMode() is either a template for use in MOBY Central services, or a Simple element for use in calling a service instance.
 
Methods inherited from class org.biomoby.shared.MobyPrimaryDataSimple
addNamespace, format, getDataType, getNamespaces, removeNamespace, removeNamespace, setDataType, setNamespaces
 
Methods inherited from class org.biomoby.shared.MobyPrimaryData
isPrimary
 
Methods inherited from class org.biomoby.shared.MobyData
getId, getName, getUserData, setUserData
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.biomoby.shared.data.MobyDataInstance
getName, getUserData, setUserData
 

Constructor Detail

MobyDataObject

public MobyDataObject(Element element)
               throws MobyException
Construct the object using a DOM fragment.

Throws:
MobyException - if the element is not an Object tag, or is missing a required attribute

MobyDataObject

public MobyDataObject(Element element,
                      Registry registry)
               throws MobyException
Throws:
MobyException

MobyDataObject

public MobyDataObject(String name)
Constructor with no instance information, just a name (which can be blank). Instance information can be filled out later with setId() and setNamespace().


MobyDataObject

public MobyDataObject(String name,
                      Registry registry)

MobyDataObject

public MobyDataObject(String namespace,
                      String id)
Constructor convenient for a base object with a namespace and ID.


MobyDataObject

public MobyDataObject(String namespace,
                      String id,
                      Registry registry)

MobyDataObject

public MobyDataObject(MobyDataObject mobj)
Creates a base object with the same name, namespace and id as the input instance, as opposed to clone, which creates an exact copy of all the fields and the datatype.

Method Detail

createInstanceFromString

public static MobyDataObject createInstanceFromString(String typeName,
                                                      String value)
                                               throws MobyException
Construct a primitive data type instance from a string value. In the case of data type "Object", the value is used as the ID.

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")

createInstanceFromString

public static MobyDataObject createInstanceFromString(String typeName,
                                                      String value,
                                                      Registry registry)
                                               throws MobyException
Throws:
MobyException

createInstanceFromDOM

public static MobyDataInstance createInstanceFromDOM(Element objectTag)
                                              throws MobyException
This method creates a MobyDataObject of the appropriate subclass for a given input XML tree (e.g. base objects like MobyDataObject and MobyDataInt, or complex objects like MobyDataDateTime or MobyDataComposite, or even a MobyDataSecondaryInstance). This method will also parse a MOBY XML Object wrapped in a Simple tag when the Simple is passed in as the main element.

Parameters:
objectTag - the W3C DOM Element node corresponding to the object's enclosing tag, or a Simple tag
Throws:
MobyException

createInstanceFromDOM

public static MobyDataInstance createInstanceFromDOM(Element objectTag,
                                                     Registry registry)
                                              throws MobyException
Throws:
MobyException

setName

public void setName(String name)
Please note that you almost never want to call this method in a client. The articleName of a MOBY Ontology object is normally fully determined by either the parameter name in the service being called (MobyContentInstance handles this), or the member field name when included as part of a composite object (MobyDataComposite handles this).

Specified by:
setName in interface MobyDataInstance
Overrides:
setName in class MobyData

getTextContents

public static String getTextContents(Element element)
Similar to DOM level 3 getTextContent, but only elements are excepted as input, and text inside children elements is not picked up. Actually calls MobyObjectDecompositionImpl.getTextContent()


getName

public static String getName(Element e)
Determine the name of the element if an enclosing tag (e.g. Simple or composite class) exists


getId

public static String getId(Element e)

createInstanceFromXML

public static MobyDataInstance createInstanceFromXML(String mobyXML)
                                              throws IllegalArgumentException
Similar to createObjectFromDOM(), but parses the XML for you using the JAXP parser discovery mechanism. NOT YET IMPLEMENTED.

Throws:
IllegalArgumentException

equals

public boolean equals(Object passedInObject)
               throws ClassCastException
Used to see if two objects are equivalent. If the passed in object is a MobyDataObject, its getObject() value will be used for the comparison. The namespace and ID are ignored, only the value is compared (such as a MobyDataInteger or Integer or BigInteger vs. a MobyDataInteger).

Overrides:
equals in class Object
Returns:
true if the values are equals according to the underlying Java object's equals() method
Throws:
ClassCastException - if and only if a child class or underlying Java object decides the comparison classes are invalid

compareTo

public int compareTo(Object o)
This method lexically compares in the order of value, ID, name if passed in object is a MobyDataObject. Otherwise it returns -1 (null fields get pushed to the end of the list). Child classes are encouraged to override this method for numerical comparison, etc. where appropriate, falling back to this method if the result is 0.

Specified by:
compareTo in interface Comparable

setXmlMode

public void setXmlMode(int mode)
                throws IllegalArgumentException
Determined whether toXML will return a Central template value or a service call instance value.

Specified by:
setXmlMode in interface MobyDataInstance
Parameters:
mode - one of MobyDataInstance.CENTRAL_XML_MODE or MobyDataInstance.SERVICE_XML_MODE
Throws:
IllegalArgumentException - if the mode is not one of the specified values

getXmlMode

public int getXmlMode()
Report whether toXML will produce Central template or service call instance XML.

Specified by:
getXmlMode in interface MobyDataInstance
Returns:
one of MobyDataInstance.CENTRAL_XML_MODE or MobyDataInstance.SERVICE_XML_MODE

getObject

public Object getObject()
Gives access to the Java object instance underlying the MobyData instance. For example, to change a MOBY String object, call ((StringBuffer) (data.getObject()).append("extra text to add to the end") In the case of a base Moby Object, there really is no underlying Java equivalent to return, so a java.lang.Object is returned for completeness's sake. possibly useful for notification events and pointer equivalency testing in derived classes such as MobyDataServiceAssocInstance?

Specified by:
getObject in interface MobyDataInstance

getValue

public String getValue()
A lexical (prefereably human readable) representation of the underlying object value (not including the namespace and ID). This value is used in sorting, and potentially for user interface elements such as tool tips and comment fields. For base objects, there is no underlying value (just a namespace and id), so the result is always a constant string "[Object]".


addCrossReferences

public void addCrossReferences(Element e)
                        throws MobyException
Throws:
MobyException

addCrossReferences

public void addCrossReferences(Element e,
                               Registry reg)
                        throws MobyException
Throws:
MobyException

addCrossReference

public void addCrossReference(MobyDataObject mdsi)
                       throws NullPointerException
Throws:
NullPointerException

getCrossReferences

public Collection getCrossReferences()
Call this method if you would like to modify the cross references, such as removing items, clearing the collection, etc. Be sure only to add MobyDataXref and MobyDataObject to the collecton or you'll have a type casting problem later! When we start requiring Java 1.5, this Collection will have a Generic template applied to it.


hasCrossReferences

public boolean hasCrossReferences()

addProvisionInfo

public void addProvisionInfo(Element e)
                      throws MobyException
Throws:
MobyException

setProvisionInfo

public void setProvisionInfo(MobyProvisionInfo info)

getProvisionInfo

public MobyProvisionInfo getProvisionInfo()

setId

public void setId(String value)
Used to set the data instance value based on an ID string. i.e. just an Object.

Overrides:
setId in class MobyData

toString

public String toString()
Convenience method to get the basic XML representation

Overrides:
toString in class MobyPrimaryDataSimple
Returns:
the raw XML representation of the object

clone

public MobyDataObject clone()
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 MobyDataObject.

Overrides:
clone in class MobyPrimaryDataSimple
Returns:
an object of class MobyDataObject

setPrimaryNamespace

public void setPrimaryNamespace(MobyNamespace ns)
This sets the namespace that will be used in toXML(), since in the XML representation for service execution, you can only have one namespace. If this namespace is not already part of the namespaces for this object, it will be added. By default, if this method isn't called, the first namespace in the namespace array will be used, and in fact this method rearranges the array to have the desired effect.


getPrimaryNamespace

public MobyNamespace getPrimaryNamespace()

toXML

public String toXML()
Produces a full-blown XML fragment that depending on the value of getXmlMode() is either a template for use in MOBY Central services, or a Simple element for use in calling a service instance.

Specified by:
toXML in interface MobyDataInstance
Overrides:
toXML in class MobyPrimaryDataSimple
Returns:
the MOBY XML representation of the data instance

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010