Public:BWmeta service/Transformers
From YaddaWiki
Service details | |
---|---|
Name | BWmeta |
Code location (relative to SVN root) | projects/dir/bwmeta-core |
Javadoc | |
Contact person | Jakub 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 | ||||
1.2.0 | ||||
2.0.0 |
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 typeT
from aString
or aReader
-
IMetadataWriter<T>
serializes an object of typeT
to aString
or aWriter
-
IMetadataModelConverter<S, T>
converts an object of typeS
to an object of typeT
-
IMetadataFormatConverter
converts serialized metadata from one format to another one
See detailed description of transformers interface below.
Existing transformers in YADDA
Existing transformers are located in the pl.edu.icm.yadda.bwmeta.transformers
package.
Readers:
Class name | Format | Model |
---|---|---|
Bwmeta1_0ToDLTransformer | BWmeta 1.0 | DL |
Bwmeta1_0ToRepoTransformer | BWmeta 1.0 | Repo |
Bwmeta1_2ToYTransformer | BWmeta 1.2 | Y |
Bwmeta2_0ToYTransfomrer | BWmeta 2.0 | Y |
Writers:
Class name | Model | Format |
---|---|---|
DLToBwmeta1_0Transformer | DL | BWmeta 1.0 |
RepoToBwmeta1_0Transformer | Repo | BWmeta 1.0 |
YToBwmeta1_2Transformer | Y | BWmeta 1.2 |
YToBwmeta2_0Transformer | Y | BWmeta 2.0 |
Model converters:
Class name | Source model | Target model |
---|---|---|
DLToYTransformer | DL | Y |
YToDLTransformer | Y | DL |
MetadataTransformerFactory
MetadataTransformerFactory
maintains a list of available "atomic" transformers
and is able to combine the atomic transformers into more complex ones.
MetadataTransformerFactory in YADDA
There is a static instantion of MetadataTransformerFactory pl.edu.icm.yadda.bwmeta.transformers.BwmetaTransformers.BTF
, which can be used in many typical situations. New transformers should be added to this factory.
See detailed description of MetadataTransformerFactory below.
Description of transformers interface
Classes listed in Unified interface section provide following methods:
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 fromreader
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 inobjects
list; returns a string contains all metadata -
void write(Writer writer, List<T> objects, Object... hints) throws TransformationException
-- serializes metadata model objects given inobjects
list; the result is written intowriter
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 insource
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 streamfrom
; metadata in target format are written into ato
stream.
Description of 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)