org.embl.ebi.escience.baclava
Class DataThing

java.lang.Object
  extended by org.embl.ebi.escience.baclava.DataThing
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class DataThing
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A simple wrapper around an arbitrary Collection object which allows lookup and storage of any metadata within the collection or its children. In addition, there is an object of metadata concerning the DataThing itself. You obtain a DataThing by invoking the bake operation on the DataThingFactory in the factory subpackage, this is to allow the factory to sensibly configure such things as types and underlying collections.

Author:
Tom Oinn
See Also:
Serialized Form

Field Summary
static java.util.Properties mimeTypes
           
static LSIDProvider SYSTEM_DEFAULT_LSID_PROVIDER
           
 
Constructor Summary
DataThing(DataThing other)
           
DataThing(org.jdom.Element e)
          Construct a new DataThing from the supplied XML Jdom Element.
DataThing(java.lang.Object o)
          Create and bind a new SemanticMarkup object to the DataThing itself, it's not totally clear there's a need for this but it does no harm so why not?
 
Method Summary
 java.util.Iterator<DataThing> childIterator()
          Iterate over all imediate children.
 java.lang.Object clone()
           
 void copyMetadataFrom(DataThing source)
          Copy the markup from the supplied DataThing object to this one.
 DataThing drillAndSet(DataThing oldDT, java.lang.String newData)
          Drill into a collection searching for a data-object that has the same data with oldDT and replace its data with newData.
 DataThing extractChild(java.lang.Object child)
          Extract a child object as a DataThing.
 void fillLSIDValues()
          Populate all unassigned LSID values using the system default LSID provider
 void fillLSIDValues(LSIDProvider provider)
          Populate all unassigned LSID values in the LSID map from the supplied LSIDProvider.
 java.lang.String[] getAllLSIDs()
          Return an array of all the LSIDs that this DataThing's LSID map contains as values
 java.lang.Object getDataObject()
          Get the underlying data object, this is the first level of the data document.
 java.lang.Object getDataObjectWithLSID(java.lang.String LSID)
          Get the object with the supplied LSID or return null if there isn't one
 org.jdom.Element getElement()
          Return the JDom Element corresponding to this DataThing represented as XML
 javax.swing.ImageIcon getIcon()
          Get a display icon for this DataThing, currently this is based on the MIME type from the syntactic type string.
 java.lang.String getLSID(java.lang.Object target)
          Get the LSID of the named object, returns the empty string if there is no such mapping
 java.util.Map<java.lang.Object,java.lang.String> getLSIDMap()
          Get the LSID map object->LSID
 SemanticMarkup getMetadata()
          Return the SemanticMarkup object associated with the DataThing itself
 SemanticMarkup getMetadataForObject(java.lang.Object theObject, boolean supplyDefault)
          Get the SemanticMarkup associated with an object in this DataThing.
 java.lang.String getMostInterestingMIMETypeForObject(java.lang.Object o)
           
 java.lang.String getSyntacticType()
          Get the syntax type of this DataThing.
 java.lang.String getSyntacticTypeForObject(java.lang.Object o)
           
 BaclavaIterator iterator(java.lang.String desiredType)
          Given a desired type, return the BaclavaIterator that provides DataThing objects of this type.
 void linkMetadataFrom(DataThing source)
          Link the metadata of this object to the specified datathing, similar in effect to the copy operation above in most cases but doesn't deep copy the metadata.
 void setLSID(java.lang.Object target, java.lang.String id)
          Set the LSID of the named object to the specified value.
 java.lang.String toString()
           
static java.io.File writeObjectToFileSystem(java.io.File destination, java.lang.String name, java.lang.Object o, java.lang.String defaultExtension)
          Write a specific object to the filesystem this has no access to metadata about the object and so is not particularly clever.
 java.io.File writeToFileSystem(java.io.File destination, java.lang.String name)
          Writes the contents of the DataThing into the specified directory using the given name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SYSTEM_DEFAULT_LSID_PROVIDER

public static LSIDProvider SYSTEM_DEFAULT_LSID_PROVIDER

mimeTypes

public static java.util.Properties mimeTypes
Constructor Detail

DataThing

public DataThing(DataThing other)

DataThing

public DataThing(org.jdom.Element e)
Construct a new DataThing from the supplied XML Jdom Element. Delegates to the DataThingXMLFactory for almost all the real work here.


DataThing

public DataThing(java.lang.Object o)
Create and bind a new SemanticMarkup object to the DataThing itself, it's not totally clear there's a need for this but it does no harm so why not?

Method Detail

getLSIDMap

public java.util.Map<java.lang.Object,java.lang.String> getLSIDMap()
Get the LSID map object->LSID


fillLSIDValues

public void fillLSIDValues()
Populate all unassigned LSID values using the system default LSID provider


fillLSIDValues

public void fillLSIDValues(LSIDProvider provider)
Populate all unassigned LSID values in the LSID map from the supplied LSIDProvider. This traverses the object contained within the DataThing as well as the DataThing itself and provides LSID values where there are none defined.


setLSID

public void setLSID(java.lang.Object target,
                    java.lang.String id)
Set the LSID of the named object to the specified value.


getLSID

public java.lang.String getLSID(java.lang.Object target)
Get the LSID of the named object, returns the empty string if there is no such mapping


getDataObjectWithLSID

public java.lang.Object getDataObjectWithLSID(java.lang.String LSID)
Get the object with the supplied LSID or return null if there isn't one


getAllLSIDs

public java.lang.String[] getAllLSIDs()
Return an array of all the LSIDs that this DataThing's LSID map contains as values


getIcon

public javax.swing.ImageIcon getIcon()
Get a display icon for this DataThing, currently this is based on the MIME type from the syntactic type string.


getMetadata

public SemanticMarkup getMetadata()
Return the SemanticMarkup object associated with the DataThing itself


getDataObject

public java.lang.Object getDataObject()
Get the underlying data object, this is the first level of the data document.


getSyntacticType

public java.lang.String getSyntacticType()
Get the syntax type of this DataThing. The type string is based around application of the collection type constructors to a base MIME type. For example, t(s('text/plain')) is a tree of sets of TEXT/PLAIN items. The MIME type may be a comma separated list of types. Possible type constructors are t(..) for trees, s(..) for sets, l(..) for lists and p(..) for partial orders.

I would imagine that we'll mostly be dealing with types of 'text/plain', lists of same and maybe the occasional 'image/png' or similar, but I think this has enough flexibility to cover most things.

The type string "null" represents and empty DataThing and is the default value returned if the collection is empty.


getMostInterestingMIMETypeForObject

public java.lang.String getMostInterestingMIMETypeForObject(java.lang.Object o)

getSyntacticTypeForObject

public java.lang.String getSyntacticTypeForObject(java.lang.Object o)

copyMetadataFrom

public void copyMetadataFrom(DataThing source)
Copy the markup from the supplied DataThing object to this one. This is mainly used when the data has been repackaged, to preserve eg. LSID values.


linkMetadataFrom

public void linkMetadataFrom(DataThing source)
Link the metadata of this object to the specified datathing, similar in effect to the copy operation above in most cases but doesn't deep copy the metadata.


getMetadataForObject

public SemanticMarkup getMetadataForObject(java.lang.Object theObject,
                                           boolean supplyDefault)
                                    throws NoMetadataFoundException
Get the SemanticMarkup associated with an object in this DataThing. If there is no such metadata available the behavious depends upon the value of the supplyDefaults parameter. If false, then a NoMetadataFoundException is thrown, if true a new SemanticMarkup object is created, stored in the dictionary and returned to the caller.

Throws:
NoMetadataFoundException

getElement

public org.jdom.Element getElement()
Return the JDom Element corresponding to this DataThing represented as XML


extractChild

public DataThing extractChild(java.lang.Object child)
Extract a child object as a DataThing. This assumes that the object referenced is actually within this DataThing object, behaviour is undefined otherwise. Although we could check this and impose it as a constraint the performance hit of traversing the entire original DataThing collection structure and doing potentially expensive equivalence computations is probably not worth it. Use with care.

Returns:
a view on an object contained within this DataThing as a new DataThing

childIterator

public java.util.Iterator<DataThing> childIterator()
Iterate over all imediate children. If there are no children, return an iterator over nothing. All children will be viewed as DataThing instances.

Returns:
an Iterator over all children

iterator

public BaclavaIterator iterator(java.lang.String desiredType)
                         throws java.beans.IntrospectionException
Given a desired type, return the BaclavaIterator that provides DataThing objects of this type. If the desired collection structure is not contained by this DataThing then an exception is thrown.

Throws:
java.beans.IntrospectionException - thrown if the supplied type is not contained within the current DataThing type.

drillAndSet

public DataThing drillAndSet(DataThing oldDT,
                             java.lang.String newData)
Drill into a collection searching for a data-object that has the same data with oldDT and replace its data with newData.

Returns:
true if a datathing's dataObject has been replaced with the newData.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

writeToFileSystem

public java.io.File writeToFileSystem(java.io.File destination,
                                      java.lang.String name)
                               throws java.io.IOException
Writes the contents of the DataThing into the specified directory using the given name. If there is only one item a single file is created otherwise a directory structure mirroring the collection structure is built. A File object representing the file or directory that has been written is returned.

Throws:
java.io.IOException

writeObjectToFileSystem

public static java.io.File writeObjectToFileSystem(java.io.File destination,
                                                   java.lang.String name,
                                                   java.lang.Object o,
                                                   java.lang.String defaultExtension)
                                            throws java.io.IOException
Write a specific object to the filesystem this has no access to metadata about the object and so is not particularly clever. A File object representing the file or directory that has been written is returned.

Throws:
java.io.IOException

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object