Public:BWmeta service/Transformers

From YaddaWiki

(Difference between revisions)
Jump to: navigation, search
(Unified interface (under construction))
Line 1: Line 1:
{{Infobox BWmeta service}}
{{Infobox BWmeta service}}
-
== Background and motivation ==
+
=== Background and motivation ===
As of 2010Q4, three versions of BWmeta format and at least three Java models of BWmeta are used in YADDA.
As of 2010Q4, three versions of BWmeta format and at least three Java models of BWmeta are used in YADDA.
Line 31: Line 31:
A unified interface to all the transformations would be very helpful.
A unified interface to all the transformations would be very helpful.
-
== Unified interface (under construction) ==
+
=== Unified interface ===
Four different transformer types are present: readers, writers and model converters and format converters.  Each type has a corresponding interface:
Four different transformer types are present: readers, writers and model converters and format converters.  Each type has a corresponding interface:
Line 37: Line 37:
* <code>IMetadataWriter&lt;T&gt;</code> serializes an object of type <code>T</code> to a <code>String</code> or a <code>Writer</code>
* <code>IMetadataWriter&lt;T&gt;</code> serializes an object of type <code>T</code> to a <code>String</code> or a <code>Writer</code>
* <code>IMetadataModelConverter&lt;S, T&gt;</code> converts an object of type <code>S</code> to an object of type <code>T</code>
* <code>IMetadataModelConverter&lt;S, T&gt;</code> converts an object of type <code>S</code> to an object of type <code>T</code>
-
* <code>IMetadataFormatConverter</code>  
+
* <code>IMetadataFormatConverter</code> converts serialized metadata from one format to another one
<code>MetadataTransformerFactory</code> maintains a list of available "atomic" transformers
<code>MetadataTransformerFactory</code> maintains a list of available "atomic" transformers
and is able to combine the atomic transformers into more complex ones.
and is able to combine the atomic transformers into more complex ones.
 +
 +
== Transformers interface ==
 +
 +
<code>IMetadataReader&lt;T&gt;</code> (T is a model class)
 +
* <code>MetadataFormat getSourceFormat()</code> -- return the source format
 +
* <code>MetadataModel&lt;T&gt; getTargetModel()</code> -- returns the target model
 +
* <code>List<T> read(String string, Object... hints) throws TransformationException</code> -- deserializes metadata from string; returns a list of model objects.
 +
* <code>List<T> read(Reader reader, Object... hints) throws TransformationException</code> -- deserializes metadata from <code>reader</code> stream; returns a list of model objects.
 +
 +
<code>IMetadataWriter&lt;T&gt;</code>
 +
* <code>MetadataModel&lt;T&gt; getSourceModel()</code> -- returns the source model
 +
* <code>MetadataFormat getTargetFormat()</code> -- returns the target format
 +
* <code>String write(List&lt;T&gt; objects, Object... hints) throws TransformationException</code> -- serializes metadata model objects given in <code>objects</code> list; returns a string contains all metadata
 +
* <code>void write(Writer writer, List&lt;T&gt; objects, Object... hints) throws TransformationException</code> -- serializes metadata model objects given in <code>objects</code> list; the result is written into <code>writer</code> stream.
 +
 +
<code>IMetadataModelConverter&lt;S, T&gt;</code>
 +
* <code>MetadataModel&lt;S&gt; getSourceModel()</code> -- returns the source model
 +
* <code>MetadataModel&lt;T&gt; </code> -- returns the target model
 +
* <code>T convert(S source, Object... hints) throws TransformationException;</code> -- converts a metadata object of type S into objects of type T
 +
 +
<code>IMetadataFormatConverter</code>
 +
* <code>MetadataFormat getSourceFormat()</code> -- returns the source format
 +
* <code>MetadataFormat getTargetFormat()</code> -- returns the target format
 +
* <code>String convert(String source, Object... hints) throws TransformationException</code> -- converts serialized metadata given in <code>source</code> string; returns a string containing metadata in target format
 +
* <code>void convert(Reader from, Writer to, Object... hints) throws TransformationException</code> -- converts serialized metadata read from a stream <code>from</code>; metadata in target format are written into a <code>to</code> stream.
 +
 +
== MetadataTransformerFactory interface ==
Public constructors provided by <code>MetadataTransformerFactory</code>:
Public constructors provided by <code>MetadataTransformerFactory</code>:

Revision as of 11:00, 31 December 2010

Service details
NameBWmeta
Code location
(relative to SVN root)
projects/dir/bwmeta-core
Javadoc
Contact personJakub Jurkiewicz

Contents

Background and motivation

As of 2010Q4, three versions of BWmeta format and at least three Java models of BWmeta are used in YADDA. See here for details. Serialization and deserialization is implemented for the following pairs:

Repo DL Y
1.0.5 Image:Tick.png Image:Tick.png
1.2.0 Image:Tick.png
2.0.0 Image:Tick.png

There are also converters between selected models:

  • Y ↔ DL

Serialization of Y model to BWmeta 1.0.5 is therefore possible through the following chain of transformations:

  • Y model → DL model → BWmeta 1.0.5

Conversion from DL model to Repo model is possible through:

  • DL model → BWmeta 1.0.5 → Repo model

Unfortunately, many mutually-incompatible transformation interfaces are present. It is difficult to understand which transformations are possible, how to combine them, which classes should be used for that end and how to instantiate the classes.

A unified interface to all the transformations would be very helpful.

Unified interface

Four different transformer types are present: readers, writers and model converters and format converters. Each type has a corresponding interface:

  • IMetadataReader<T> deserializes an object of type T from a String or a Reader
  • IMetadataWriter<T> serializes an object of type T to a String or a Writer
  • IMetadataModelConverter<S, T> converts an object of type S to an object of type T
  • IMetadataFormatConverter converts serialized metadata from one format to another one

MetadataTransformerFactory maintains a list of available "atomic" transformers and is able to combine the atomic transformers into more complex ones.

Transformers interface

IMetadataReader<T> (T is a model class)

  • MetadataFormat getSourceFormat() -- return the source format
  • MetadataModel<T> getTargetModel() -- returns the target model
  • List<T> read(String string, Object... hints) throws TransformationException -- deserializes metadata from string; returns a list of model objects.
  • List<T> read(Reader reader, Object... hints) throws TransformationException -- deserializes metadata from reader stream; returns a list of model objects.

IMetadataWriter<T>

  • MetadataModel<T> getSourceModel() -- returns the source model
  • MetadataFormat getTargetFormat() -- returns the target format
  • String write(List<T> objects, Object... hints) throws TransformationException -- serializes metadata model objects given in objects list; returns a string contains all metadata
  • void write(Writer writer, List<T> objects, Object... hints) throws TransformationException -- serializes metadata model objects given in objects list; the result is written into writer stream.

IMetadataModelConverter<S, T>

  • MetadataModel<S> getSourceModel() -- returns the source model
  • MetadataModel<T> -- returns the target model
  • T convert(S source, Object... hints) throws TransformationException; -- converts a metadata object of type S into objects of type T

IMetadataFormatConverter

  • MetadataFormat getSourceFormat() -- returns the source format
  • MetadataFormat getTargetFormat() -- returns the target format
  • String convert(String source, Object... hints) throws TransformationException -- converts serialized metadata given in source string; returns a string containing metadata in target format
  • void convert(Reader from, Writer to, Object... hints) throws TransformationException -- converts serialized metadata read from a stream from; metadata in target format are written into a to stream.

MetadataTransformerFactory interface

Public constructors provided by MetadataTransformerFactory:

  • MetadataTransformerFactory(List<IMetadataReaders>, List<IMetadataWriters>, List<IMetadataModelConverters>, List<IMetadataFormatConverters>) -- builds a MetadataTransformerFactory from given lists of atomic transformers,
  • MetadataTransformerFactory(MetadataTransformerFactory, List<IMetadataReaders>, List<IMetadataWriters>, List<IMetadataModelConverters>, List<IMetadataFormatConverters>) -- creates a new MetadataTransformerFactory from an existing one, which contains joined lists of atomic transformers.

Public methods of MetadataTransformerFactory, that return return transformer built from atomic transformers given in object constructor:

  • <T> IMetadataReader<T> getReader(MetadataModel<T>, MetadataFormat)
  • <T> IMetadataWriter<T> getWriter(MetadataModel<T>, MetadataFormat)
  • <S, T> IMetadataModelConverter<S, T> getModelConverter(MetadataModel<S>, MetadataModel<T>)
  • IMetadataFormatConverter getFormatConverter(MetadataFormat, MetadataFormat)

MetadataTransformerFactory also contains a set of static methods compose(), that return a complex transformer built from two given transformers. These methods are not part of IMetadataTransformerFactory interface.

  • IMetadataReader compose(IMetadataFormatConverter, IMetadataReader)
  • IMetadataReader compose(IMetadataReader, IMetadataModelConverter)
  • IMetadataWriter compose(IMetadataWriter, IMetadataFormatConverter)
  • IMetadataWriter compose(IMetadataModelConverter, IMetadataWriter)
  • IMetadataFormatConverter compose(IMetadataFormatConverter, IMetadataFormatConverter)
  • IMetadataFormatConverter compose(IMetadataReader, IMetadataWriter)
  • IMetadataModelConverter compose(IMetadataModelConverter, IMetadataModelConverter)
  • IMetadataModelConverter compose(IMetadataWriter, IMetadataReader)
Personal tools