View Javadoc

1   /**
2    * Copyright (C) cedarsoft GmbH.
3    *
4    * Licensed under the GNU General Public License version 3 (the "License")
5    * with Classpath Exception; you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at
7    *
8    *         http://www.cedarsoft.org/gpl3ce
9    *         (GPL 3 with Classpath Exception)
10   *
11   * This code is free software; you can redistribute it and/or modify it
12   * under the terms of the GNU General Public License version 3 only, as
13   * published by the Free Software Foundation. cedarsoft GmbH designates this
14   * particular file as subject to the "Classpath" exception as provided
15   * by cedarsoft GmbH in the LICENSE file that accompanied this code.
16   *
17   * This code is distributed in the hope that it will be useful, but WITHOUT
18   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20   * version 3 for more details (a copy is included in the LICENSE file that
21   * accompanied this code).
22   *
23   * You should have received a copy of the GNU General Public License version
24   * 3 along with this work; if not, write to the Free Software Foundation,
25   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26   *
27   * Please contact cedarsoft GmbH, 72810 Gomaringen, Germany,
28   * or visit www.cedarsoft.com if you need additional information or
29   * have any questions.
30   */
31  
32  package com.cedarsoft.serialization;
33  
34  import com.cedarsoft.version.Version;
35  import com.cedarsoft.version.VersionException;
36  
37  import javax.annotation.Nonnull;
38  import java.io.IOException;
39  
40  /**
41   * This is a special serializer that is able to serialize an object to a given element.
42   * The pluggable serializers can be used to delegate the serialization for child objects.
43   *
44   * @param <T> the type of object this serializer is able to (de)serialize
45   * @param <S> the object to serialize to (e.g. a dom element or stream)
46   * @param <D> the object to deserialize from ((e.g. a dom element or stream)
47   * @param <E> the exception that might be thrown
48   * @param <O> the type of the object that is serialized to
49   * @param <I> the type of the object that is serialized from
50   */
51  public interface PluggableSerializer<T, S, D, E extends Throwable, O, I> extends Serializer<T,O,I> {
52    /**
53     * Serializes the object to the given element
54     * throws com.cedarsoft.version.VersionException if the version does not match
55     *
56     * @param serializeTo   the serializeTo
57     * @param object        the object
58     * @param formatVersion the format version
59     *
60     * @throws E if serialization failed
61     * @throws java.io.IOException if there is an io problem
62     */
63    void serialize( @Nonnull S serializeTo, @Nonnull T object, @Nonnull Version formatVersion ) throws IOException, VersionException, E;
64  
65    /**
66     * Deserializes the object from the given document
67     * throws com.cedarsoft.version.VersionException if the version does not match
68     *
69     * @param deserializeFrom the deserializeFrom
70     * @param formatVersion   the format version
71     * @return the deserialized object
72     *
73     * @throws E if deserialization failed
74     * @throws java.io.IOException if there is an io problem
75     */
76    @Nonnull
77    T deserialize( @Nonnull D deserializeFrom, @Nonnull Version formatVersion ) throws IOException, VersionException, E;
78  }