001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     dmetzler
018 */
019package org.nuxeo.ecm.automation.jaxrs;
020
021import java.lang.reflect.Type;
022
023import javax.ws.rs.core.Context;
024import javax.ws.rs.ext.Provider;
025
026import org.nuxeo.ecm.webengine.JsonFactoryManager;
027import org.nuxeo.runtime.api.Framework;
028
029import com.fasterxml.jackson.core.JsonFactory;
030import com.sun.jersey.core.spi.component.ComponentContext;
031import com.sun.jersey.core.spi.component.ComponentScope;
032import com.sun.jersey.spi.inject.Injectable;
033import com.sun.jersey.spi.inject.InjectableProvider;
034
035/**
036 * @since 5.7.3
037 */
038@Provider
039public class JsonFactoryProvider implements InjectableProvider<Context, Type>, Injectable<JsonFactory> {
040
041    @Override
042    public JsonFactory getValue() {
043        return Framework.getService(JsonFactoryManager.class).getJsonFactory();
044    }
045
046    @Override
047    public Injectable<JsonFactory> getInjectable(ComponentContext arg0, Context arg1, Type t) {
048        if (t.equals(JsonFactory.class)) {
049            return this;
050        } else {
051            return null;
052        }
053    }
054
055    @Override
056    public ComponentScope getScope() {
057        return ComponentScope.Singleton;
058    }
059
060}