1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.johnzon.jaxrs; |
20 | |
|
21 | |
import javax.ws.rs.core.MediaType; |
22 | |
import javax.ws.rs.core.MultivaluedMap; |
23 | |
import javax.ws.rs.ext.MessageBodyReader; |
24 | |
import javax.ws.rs.ext.MessageBodyWriter; |
25 | |
import java.io.IOException; |
26 | |
import java.io.InputStream; |
27 | |
import java.io.OutputStream; |
28 | |
import java.lang.annotation.Annotation; |
29 | |
import java.lang.reflect.Type; |
30 | |
|
31 | |
public abstract class DelegateProvider<T> implements MessageBodyWriter<T>, MessageBodyReader<T> { |
32 | |
private final MessageBodyReader<T> reader; |
33 | |
private final MessageBodyWriter<T> writer; |
34 | |
|
35 | 13 | protected DelegateProvider(final MessageBodyReader<T> reader, final MessageBodyWriter<T> writer) { |
36 | 13 | this.reader = reader; |
37 | 13 | this.writer = writer; |
38 | 13 | } |
39 | |
|
40 | |
@Override |
41 | |
public boolean isReadable(final Class<?> rawType, final Type genericType, |
42 | |
final Annotation[] annotations, final MediaType mediaType) { |
43 | 12 | return reader.isReadable(rawType, genericType, annotations, mediaType); |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public T readFrom(final Class<T> rawType, final Type genericType, |
48 | |
final Annotation[] annotations, final MediaType mediaType, |
49 | |
final MultivaluedMap<String, String> httpHeaders, |
50 | |
final InputStream entityStream) throws IOException { |
51 | 10 | return reader.readFrom(rawType, genericType, annotations, mediaType, httpHeaders, entityStream); |
52 | |
} |
53 | |
|
54 | |
@Override |
55 | |
public long getSize(final T t, final Class<?> rawType, final Type genericType, |
56 | |
final Annotation[] annotations, final MediaType mediaType) { |
57 | 0 | return writer.getSize(t, rawType, genericType, annotations, mediaType); |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public boolean isWriteable(final Class<?> rawType, final Type genericType, |
62 | |
final Annotation[] annotations, final MediaType mediaType) { |
63 | 12 | return writer.isWriteable(rawType, genericType, annotations, mediaType); |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
public void writeTo(final T t, final Class<?> rawType, final Type genericType, |
68 | |
final Annotation[] annotations, final MediaType mediaType, |
69 | |
final MultivaluedMap<String, Object> httpHeaders, |
70 | |
final OutputStream entityStream) throws IOException { |
71 | 10 | writer.writeTo(t, rawType, genericType, annotations, mediaType, httpHeaders, entityStream); |
72 | 10 | } |
73 | |
} |