1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.rest.repr;
21
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import java.net.URI;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Map;
28
29
30
31
32
33
34
35 public class DefaultFormat extends RepresentationFormat
36 {
37 private final RepresentationFormat inner;
38 private final Collection<MediaType> supported;
39 private final MediaType[] requested;
40
41 public DefaultFormat( RepresentationFormat inner,
42 Collection<MediaType> supported, MediaType... requested )
43 {
44 super( MediaType.APPLICATION_JSON_TYPE );
45
46 this.inner = inner;
47 this.supported = supported;
48 this.requested = requested;
49 }
50
51 @Override
52 protected String serializeValue( String type, Object value )
53 {
54 return inner.serializeValue( type, value );
55 }
56
57 @Override
58 protected ListWriter serializeList( String type )
59 {
60 return inner.serializeList( type );
61 }
62
63 @Override
64 protected MappingWriter serializeMapping( String type )
65 {
66 return inner.serializeMapping( type );
67 }
68
69 @Override
70 protected String complete( ListWriter serializer )
71 {
72 return inner.complete( serializer );
73 }
74
75 @Override
76 protected String complete( MappingWriter serializer )
77 {
78 return inner.complete( serializer );
79 }
80
81 @Override
82 public Object readValue( String input )
83 {
84 try
85 {
86 return inner.readValue( input );
87 } catch ( BadInputException e )
88 {
89 throw newMediaTypeNotSupportedException();
90 }
91 }
92
93 private MediaTypeNotSupportedException newMediaTypeNotSupportedException()
94 {
95 return new MediaTypeNotSupportedException( Response.Status.UNSUPPORTED_MEDIA_TYPE, supported, requested );
96 }
97
98 @Override
99 public Map<String, Object> readMap( String input ) throws BadInputException
100 {
101 try
102 {
103 return inner.readMap( input );
104 } catch ( BadInputException e )
105 {
106 throw newMediaTypeNotSupportedException();
107 }
108 }
109
110 @Override
111 public List<Object> readList( String input ) throws BadInputException
112 {
113 try
114 {
115 return inner.readList( input );
116 } catch ( BadInputException e )
117 {
118 throw newMediaTypeNotSupportedException();
119 }
120 }
121
122 @Override
123 public URI readUri( String input ) throws BadInputException
124 {
125 try
126 {
127 return inner.readUri( input );
128 } catch ( BadInputException e )
129 {
130 throw newMediaTypeNotSupportedException();
131 }
132 }
133 }