wsdor/src/main/java/cz/xelfi/quoridor/webidor/JAXBContextResolver.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 14 Sep 2010 08:56:13 +0200
changeset 264 d60370059c3c
parent 256 1758a7727278
permissions -rw-r--r--
Changing headers to GPLv3
jtulach@35
     1
/*
jaroslav@264
     2
 * Quoridor server and related libraries
jaroslav@264
     3
 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@35
     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@264
     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@264
    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/.
jtulach@35
    17
 */
jtulach@35
    18
jtulach@35
    19
package cz.xelfi.quoridor.webidor;
jtulach@35
    20
jtulach@35
    21
import com.sun.jersey.api.json.JSONConfiguration;
jtulach@35
    22
import com.sun.jersey.api.json.JSONJAXBContext;
jtulach@35
    23
import java.util.Arrays;
jtulach@35
    24
import java.util.HashSet;
jtulach@35
    25
import java.util.Set;
jtulach@35
    26
import javax.ws.rs.ext.ContextResolver;
jtulach@35
    27
import javax.ws.rs.ext.Provider;
jtulach@35
    28
import javax.xml.bind.JAXBContext;
jtulach@35
    29
jtulach@35
    30
/**
jtulach@35
    31
 *
jtulach@35
    32
 * @author japod
jtulach@35
    33
 */
jtulach@35
    34
@Provider
jtulach@35
    35
public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
jtulach@35
    36
    
jtulach@35
    37
    private final JAXBContext context;
jtulach@35
    38
    
jtulach@35
    39
    private final Set<Class> types;
jtulach@35
    40
    
jtulach@77
    41
    private final Class[] cTypes = {Game.class, GameId.class, GameStatus.class };
jtulach@35
    42
    
jtulach@35
    43
    public JAXBContextResolver() throws Exception {
jtulach@35
    44
        this.types = new HashSet(Arrays.asList(cTypes));
jtulach@35
    45
        this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
jtulach@35
    46
    }
jtulach@35
    47
    
jtulach@35
    48
    public JAXBContext getContext(Class<?> objectType) {
jtulach@35
    49
        return (types.contains(objectType)) ? context : null;
jtulach@35
    50
    }
jtulach@35
    51
}