1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.datacollection.agent.rest;
20
21 import javax.ws.rs.ext.ContextResolver;
22 import javax.ws.rs.ext.Provider;
23 import javax.xml.bind.JAXBContext;
24 import javax.xml.bind.JAXBException;
25
26 import com.sun.jersey.api.json.JSONConfiguration;
27 import com.sun.jersey.api.json.JSONJAXBContext;
28
29 @Provider
30 public class ContextProvider implements ContextResolver<JAXBContext> {
31
32 private final JAXBContext context;
33 private Class<?>[] types = { };
34
35
36
37
38 public ContextProvider() throws JAXBException {
39 this.context = new JSONJAXBContext(JSONConfiguration.natural().build(),
40 types);
41 }
42
43 public JAXBContext getContext(Class<?> objectType) {
44 for (Class<?> type : types) {
45 if (type.equals(objectType))
46 return context;
47 }
48 return null;
49 }
50 }