package com.k_int.ciim;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

import com.k_int.ciim.json.CIIMGroupJSON;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;

@Provider
public class JAXBContextResolver implements ContextResolver<JAXBContext> 
{
    private JAXBContext context;
    private Class<?>[] types = { Groups.class, CIIMGroupJSON.class, GroupObjects.class}; 

    public JAXBContextResolver() throws Exception 
    {
        //JSONConfiguration config = JSONConfiguration.natural().build();
    	JSONConfiguration config = JSONConfiguration.mapped().arrays("results","relationships","attachments").build();
        context = new JSONJAXBContext(config, types);
    } 

    public JAXBContext getContext(Class<?> objectType) 
    {
        for (Class<?> type : types) 
        {
            if (type == objectType) 
            {
                return context;
            }
        }
        return null;
    }
}
