Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
Serializer | 38 | 0 | - | 0 | 0 |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.store.serialization; | |
21 | ||
22 | import java.io.IOException; | |
23 | import java.io.InputStream; | |
24 | ||
25 | import org.xwiki.component.annotation.ComponentRole; | |
26 | ||
27 | /** | |
28 | * A generic thing for converting objects of a known type into InputStreams and back again. | |
29 | * | |
30 | * @param <R> The class of object which the serializer can serialize (what it requires). | |
31 | * @param <P> The class of object which will be provided by this serializer when it parses data. | |
32 | * @version $Id: 9cbb2336cb0e115ebc2b6f673347eaa6c66fde8e $ | |
33 | * @since 3.0M2 | |
34 | */ | |
35 | // Note: We cannot replace @ComponentRole with @Role ATM since @Role supports generics and we have | |
36 | // Serializer<R, P extends R>. Changing it will thus break all code looking up components implementing this role. | |
37 | @ComponentRole | |
38 | public interface Serializer<R, P extends R> | |
39 | { | |
40 | /** | |
41 | * Parse an InputStream and create a new object. | |
42 | * | |
43 | * @param stream an InputStream to parse. | |
44 | * @return a new object made by parsing the stream. | |
45 | * @throws IOException if the InputStream does not contain the type of object | |
46 | * handled by this serializer, the object was serialized with | |
47 | * a different Serializer, or something goes wrong along the way. | |
48 | */ | |
49 | P parse(InputStream stream) throws IOException; | |
50 | ||
51 | /** | |
52 | * Serialize the given object and return an InputStream. | |
53 | * | |
54 | * @param object the thing to serialize. | |
55 | * @return an InputStream which can be used to create a new object using parse(). | |
56 | * @throws IOException if something goes wrong while serializing. | |
57 | */ | |
58 | InputStream serialize(R object) throws IOException; | |
59 | } |