Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / io / CDMPherogramAlignmentObjectTranslator.java
1 // $Id$
2 /**
3 * Copyright (C) 2016 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.molecular.io;
11
12
13 import info.bioinfweb.commons.io.XMLUtils;
14 import info.bioinfweb.jphyloio.ReaderStreamDataProvider;
15 import info.bioinfweb.jphyloio.WriterStreamDataProvider;
16 import info.bioinfweb.jphyloio.objecttranslation.InvalidObjectSourceDataException;
17 import info.bioinfweb.jphyloio.objecttranslation.implementations.AbstractXMLObjectTranslator;
18
19 import java.io.IOException;
20
21 import javax.xml.stream.XMLEventReader;
22 import javax.xml.stream.XMLStreamException;
23 import javax.xml.stream.XMLStreamWriter;
24
25 import eu.etaxonomy.cdm.model.molecular.SingleReadAlignment;
26 import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
27
28
29
30 /**
31 * <i>JPhyloIO</i> object translator to read and write a shift list of a {@link SingleReadAlignment} object from and
32 * to <i>XML</i>.
33 *
34 * @author Ben Stöver
35 * @date 28.10.2016
36 */
37 public class CDMPherogramAlignmentObjectTranslator extends AbstractXMLObjectTranslator<SingleReadAlignment.Shift[]>
38 implements SingleReadAlignmentRDFXMLConstants {
39
40 @Override
41 public Class<SingleReadAlignment.Shift[]> getObjectClass() {
42 return SingleReadAlignment.Shift[].class;
43 }
44
45
46 @Override
47 public SingleReadAlignment.Shift[] readXMLRepresentation(XMLEventReader reader, ReaderStreamDataProvider<?> streamDataProvider)
48 throws IOException, XMLStreamException, InvalidObjectSourceDataException {
49
50 // TODO implement
51 throw new InternalError(Messages.CDMPherogramAlignmentObjectTranslator_NOT_IMPLEMENTED);
52 }
53
54
55 @Override
56 public void writeXMLRepresentation(XMLStreamWriter writer, Object object, WriterStreamDataProvider<?> streamDataProvider)
57 throws IOException, XMLStreamException, ClassCastException {
58
59 SingleReadAlignment.Shift[] shifts = (SingleReadAlignment.Shift[])object;
60 XMLUtils.writeStartElement(writer, TAG_SHIFTS);
61 for (SingleReadAlignment.Shift shift : shifts) {
62 XMLUtils.writeStartElement(writer, TAG_SHIFT);
63 XMLUtils.writeAttribute(writer, ATTR_POSITION, Integer.toString(shift.position));
64 XMLUtils.writeAttribute(writer, ATTR_SHIFT, Integer.toString(shift.shift));
65 writer.writeEndElement();
66 }
67 writer.writeEndElement();
68 }
69 }