001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     dmetzler
016 */
017package org.nuxeo.ecm.automation.jaxrs;
018
019import java.lang.reflect.Type;
020
021import javax.ws.rs.core.Context;
022import javax.ws.rs.ext.Provider;
023
024import org.codehaus.jackson.JsonFactory;
025import org.nuxeo.ecm.webengine.JsonFactoryManager;
026import org.nuxeo.runtime.api.Framework;
027
028import com.sun.jersey.core.spi.component.ComponentContext;
029import com.sun.jersey.core.spi.component.ComponentScope;
030import com.sun.jersey.spi.inject.Injectable;
031import com.sun.jersey.spi.inject.InjectableProvider;
032
033/**
034 * @since 5.7.3
035 */
036@Provider
037public class JsonFactoryProvider implements InjectableProvider<Context, Type>, Injectable<JsonFactory> {
038
039    @Override
040    public JsonFactory getValue() {
041        return Framework.getLocalService(JsonFactoryManager.class).getJsonFactory();
042    }
043
044    @Override
045    public Injectable<JsonFactory> getInjectable(ComponentContext arg0, Context arg1, Type t) {
046        if (t.equals(JsonFactory.class)) {
047            return this;
048        } else {
049            return null;
050        }
051    }
052
053    @Override
054    public ComponentScope getScope() {
055        return ComponentScope.Singleton;
056    }
057
058}