XSD Fu
XSD Fu is a Python application designed to digest OME XML schema and produce an object oriented Java infrastructure to ease work with an XML DOM tree.
Requirements:
- Python 2.4+
- Genshi 0.5
- Full checkout of the specification OME-XML repository ( http://svn.openmicroscopy.org.uk/svn/specification)
- Full checkout of the LOCI repository ( https://skyking.microscopy.wisc.edu/svn/java/trunk)
NOTE: Genshi 0.5 was released on June 9th 2008. You can either install from source or download a compatible .egg for your system on the Genshi download page.
Checking out the source
svn co http://svn.openmicroscopy.org.uk/svn/specification/Xml/xsd-fu/trunk xsd-fu
Running the code generator
If you do have Genshi already installed you can run xsd-fu script with no arguments to examine the syntax:
$ ./xsd-fu Missing subcommand! Usage: ./xsd-fu <subcommand> ... Executes an OME-XML Schema definition parsing and code generation subcommand. Available subcommands: java_classes omexml_metadata omero_metadata metadata_store metadata_retrieve metadata_aggregate enum_types enum_handlers doc_gen tab_gen debug Report bugs to OME Devel <ome-devel@lists.openmicroscopy.org.uk>
If you do not have Genshi installed you can use a downloaded Python .egg for your platform as follows:
$ export PYTHONPATH=Genshi-0.5-py2.4-linux-i686.egg $ ./xsd-fu Missing subcommand! Usage: ./xsd-fu <subcommand> ... Executes an OME-XML Schema definition parsing and code generation subcommand. Available subcommands: java_classes omexml_metadata omero_metadata metadata_store metadata_retrieve metadata_aggregate enum_types enum_handlers doc_gen tab_gen debug Report bugs to OME Devel <ome-devel@lists.openmicroscopy.org.uk>
NOTE: XsdFu is now used for many different types of code generation tasks (mostly targeted at the OMERO and Bio-Formats 4.2.0 releases) as outlined by the subcommand structure above.
Generating the OME-XML Java toolchain
We'll now outline how to generate parts of the OME-XML Java toolchain which are composed of:
- OME model objects
- Enumerations for OME model properties
- Enumeration handlers for regular expression matching of enumeration strings
- Metadata store and Metadata retrieve interfaces for all OME model properties
- Various implementations of Metadata store and/or Metadata retrieve interfaces
NOTE: All the below examples assume a full OME-XML specification Subversion checkout.
Java classes for OME model objects
$ ./xsd-fu java_classes -p 'ome.xml.model' -o $LOCI_HOME/components/ome-xml/src/ome/xml/model/ \ ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd ../../Release/2010-06/V1/ROI.xsd \ ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd
Enumeration classes for OME model properties
$ ./xsd-fu enum_types -p 'ome.xml.model.enums' -o $LOCI_HOME/components/ome-xml/src/ome/xml/model/enums/ \ ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd ../../Release/2010-06/V1/ROI.xsd \ ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd
Enumeration handlers for OME model properties
$ ./xsd-fu enum_handlers -p 'ome.xml.model.enums.handlers' -o $LOCI_HOME/components/ome-xml/src/ome/xml/model/enums/handlers/ \ ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd ../../Release/2010-06/V1/ROI.xsd \ ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd
Metadata store and Metadata retrieve interfaces
$ ./xsd-fu metadata_store ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ ./xsd-fu metadata_retrieve ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ cp MetadataStore.java MetadataRetrieve.java $LOCI_HOME/components/bio-formats/src/loci/formats/meta/
OMEXMLMetadataImpl Metadata store and Metadata retrieve implementation
$ ./xsd-fu omexml_metadata ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ ./xsd-fu metadata_aggregate ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ ./xsd-fu dummy_metadata ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ ./xsd-fu filter_metadata ../../Release/2010-06/V1/ome.xsd ../../Release/2010-06/V1/BinaryFile.xsd \ ../../Release/2010-06/V1/ROI.xsd ../../Release/2010-06/V1/SA.xsd ../../Release/2010-06/V1/SPW.xsd $ cp AggregateMetadata.java DummyMetadata.java FilterMetadata.java $LOCI_HOME/components/bio-formats/src/loci/formats/meta/ $ cp OMEXMLMetadataImpl.java $LOCI_HOME/components/bio-formats/src/loci/formats/ome/
Working with Enumerations and Enumeration Handlers
XsdFu contains a flexible, configuration driven structure to code generate enumeration regular expressions. The configuration file is located off of the xsd-fu/trunk root, in the cfg folder:
Each enumeration has a key-value listing of regular expression to exact enumeration value matches. For example:
... [Correction] ".*Pl.*Apo.*" = "PlanApo" ".*Pl.*Flu.*" = "PlanFluor" "^\\s*Vio.*Corr.*" = "VioletCorrected" ".*S.*Flu.*" = "SuperFluor" ".*Neo.*flu.*" = "Neofluar" ".*Flu.*tar.*" = "Fluotar" ".*Fluo.*" = "Fluor" ".*Flua.*" = "Fluar" "^\\s*Apo.*" = "Apo" ...
Special Thanks
A special thanks goes out to Dave Kuhlman for his fabulous work on generateDS which XSD Fu makes heavy use of internally.
See also: EnumTool, DeveloperInfo, http://genshi.edgewall.org/, http://www.rexx.com/~dkuhlman/generateDS.html
