author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Thu, 07 Jan 2010 22:34:17 +0100 | |
branch | statistics-and-elo |
changeset 178 | 4b78d4f028b3 |
child 264 | d60370059c3c |
permissions | -rw-r--r-- |
jaroslav@178 | 1 |
/* |
jaroslav@178 | 2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
jaroslav@178 | 3 |
* |
jaroslav@178 | 4 |
* The contents of this file are subject to the terms of either the GNU |
jaroslav@178 | 5 |
* General Public License Version 2 only ("GPL") or the Common |
jaroslav@178 | 6 |
* Development and Distribution License("CDDL") (collectively, the |
jaroslav@178 | 7 |
* "License"). You may not use this file except in compliance with the |
jaroslav@178 | 8 |
* License. You can obtain a copy of the License at |
jaroslav@178 | 9 |
* http://www.netbeans.org/cddl-gplv2.html |
jaroslav@178 | 10 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
jaroslav@178 | 11 |
* specific language governing permissions and limitations under the |
jaroslav@178 | 12 |
* License. When distributing the software, include this License Header |
jaroslav@178 | 13 |
* Notice in each file and include the License file at |
jaroslav@178 | 14 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
jaroslav@178 | 15 |
* particular file as subject to the "Classpath" exception as provided |
jaroslav@178 | 16 |
* by Sun in the GPL Version 2 section of the License file that |
jaroslav@178 | 17 |
* accompanied this code. If applicable, add the following below the |
jaroslav@178 | 18 |
* License Header, with the fields enclosed by brackets [] replaced by |
jaroslav@178 | 19 |
* your own identifying information: |
jaroslav@178 | 20 |
* "Portions Copyrighted [year] [name of copyright owner]" |
jaroslav@178 | 21 |
* |
jaroslav@178 | 22 |
* Contributor(s): |
jaroslav@178 | 23 |
* |
jaroslav@178 | 24 |
* Portions Copyrighted 2010 Martin Rexa |
jaroslav@178 | 25 |
*/ |
jaroslav@178 | 26 |
package cz.xelfi.quoridor.statistics; |
jaroslav@178 | 27 |
|
jaroslav@178 | 28 |
import com.sun.jersey.api.json.JSONConfiguration; |
jaroslav@178 | 29 |
import com.sun.jersey.api.json.JSONJAXBContext; |
jaroslav@178 | 30 |
import java.util.Arrays; |
jaroslav@178 | 31 |
import java.util.HashSet; |
jaroslav@178 | 32 |
import java.util.Set; |
jaroslav@178 | 33 |
import javax.ws.rs.ext.ContextResolver; |
jaroslav@178 | 34 |
import javax.ws.rs.ext.Provider; |
jaroslav@178 | 35 |
import javax.xml.bind.JAXBContext; |
jaroslav@178 | 36 |
|
jaroslav@178 | 37 |
/** |
jaroslav@178 | 38 |
* |
jaroslav@178 | 39 |
* @author Martin Rexa |
jaroslav@178 | 40 |
*/ |
jaroslav@178 | 41 |
@Provider |
jaroslav@178 | 42 |
public final class JAXBContextResolver implements ContextResolver<JAXBContext> { |
jaroslav@178 | 43 |
|
jaroslav@178 | 44 |
private final JAXBContext context; |
jaroslav@178 | 45 |
|
jaroslav@178 | 46 |
private final Set<Class> types; |
jaroslav@178 | 47 |
|
jaroslav@178 | 48 |
private final Class[] cTypes = {EloList.class, EloEntry.class, OpeningNodeView.class, OpeningNodeViewEntry.class}; |
jaroslav@178 | 49 |
|
jaroslav@178 | 50 |
public JAXBContextResolver() throws Exception { |
jaroslav@178 | 51 |
this.types = new HashSet(Arrays.asList(cTypes)); |
jaroslav@178 | 52 |
this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes); |
jaroslav@178 | 53 |
} |
jaroslav@178 | 54 |
|
jaroslav@178 | 55 |
public JAXBContext getContext(Class<?> objectType) { |
jaroslav@178 | 56 |
return (types.contains(objectType)) ? context : null; |
jaroslav@178 | 57 |
} |
jaroslav@178 | 58 |
} |