statistics/src/main/java/cz/xelfi/quoridor/statistics/JAXBContextResolver.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 178 4b78d4f028b3
permissions -rw-r--r--
Changing headers to GPLv3
jaroslav@178
     1
/*
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@178
     4
 *
jaroslav@264
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@264
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@264
     7
 * the Free Software Foundation, either version 3 of the License.
jaroslav@178
     8
 *
jaroslav@264
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@264
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@264
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@264
    12
 * GNU General Public License for more details.
jaroslav@178
    13
 *
jaroslav@264
    14
 * You should have received a copy of the GNU General Public License
jaroslav@264
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@264
    16
 * If not, see http://www.gnu.org/licenses/.
jaroslav@178
    17
 */
jaroslav@178
    18
package cz.xelfi.quoridor.statistics;
jaroslav@178
    19
jaroslav@178
    20
import com.sun.jersey.api.json.JSONConfiguration;
jaroslav@178
    21
import com.sun.jersey.api.json.JSONJAXBContext;
jaroslav@178
    22
import java.util.Arrays;
jaroslav@178
    23
import java.util.HashSet;
jaroslav@178
    24
import java.util.Set;
jaroslav@178
    25
import javax.ws.rs.ext.ContextResolver;
jaroslav@178
    26
import javax.ws.rs.ext.Provider;
jaroslav@178
    27
import javax.xml.bind.JAXBContext;
jaroslav@178
    28
jaroslav@178
    29
/**
jaroslav@178
    30
 *
jaroslav@178
    31
 * @author Martin Rexa
jaroslav@178
    32
 */
jaroslav@178
    33
@Provider
jaroslav@178
    34
public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
jaroslav@178
    35
jaroslav@178
    36
    private final JAXBContext context;
jaroslav@178
    37
jaroslav@178
    38
    private final Set<Class> types;
jaroslav@178
    39
jaroslav@178
    40
    private final Class[] cTypes = {EloList.class, EloEntry.class, OpeningNodeView.class, OpeningNodeViewEntry.class};
jaroslav@178
    41
jaroslav@178
    42
    public JAXBContextResolver() throws Exception {
jaroslav@178
    43
        this.types = new HashSet(Arrays.asList(cTypes));
jaroslav@178
    44
        this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
jaroslav@178
    45
    }
jaroslav@178
    46
jaroslav@178
    47
    public JAXBContext getContext(Class<?> objectType) {
jaroslav@178
    48
        return (types.contains(objectType)) ? context : null;
jaroslav@178
    49
    }
jaroslav@178
    50
}