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.restapi.server.jaxrs;
018
019import java.util.LinkedHashSet;
020import java.util.Set;
021
022import org.nuxeo.ecm.automation.jaxrs.io.documents.BusinessAdapterListWriter;
023import org.nuxeo.ecm.automation.jaxrs.io.documents.JsonESDocumentWriter;
024import org.nuxeo.ecm.automation.jaxrs.io.operations.MultiPartFormRequestReader;
025import org.nuxeo.ecm.automation.jaxrs.io.operations.MultiPartRequestReader;
026import org.nuxeo.ecm.restapi.jaxrs.io.conversion.ConversionScheduledWriter;
027import org.nuxeo.ecm.restapi.jaxrs.io.conversion.ConversionStatusWriter;
028import org.nuxeo.ecm.restapi.jaxrs.io.types.DocumentTypeWriter;
029import org.nuxeo.ecm.restapi.jaxrs.io.types.DocumentTypesWriter;
030import org.nuxeo.ecm.restapi.jaxrs.io.types.FacetWriter;
031import org.nuxeo.ecm.restapi.jaxrs.io.types.FacetsWriter;
032import org.nuxeo.ecm.restapi.jaxrs.io.types.SchemaWriter;
033import org.nuxeo.ecm.restapi.jaxrs.io.types.SchemasWriter;
034import org.nuxeo.ecm.webengine.app.WebEngineModule;
035import org.nuxeo.ecm.webengine.jaxrs.coreiodelegate.JsonCoreIODelegate;
036
037/**
038 * @since 5.8
039 */
040public class APIModule extends WebEngineModule {
041
042    @Override
043    public Set<Class<?>> getClasses() {
044        Set<Class<?>> result = super.getClasses();
045        // need to be stateless since it needs the request member to be
046        // injected
047        result.add(MultiPartRequestReader.class);
048        result.add(MultiPartFormRequestReader.class);
049        return result;
050    }
051
052    @Override
053    public Set<Object> getSingletons() {
054        Set<Object> result = new LinkedHashSet<Object>();
055
056        // writers
057        result.add(new JsonESDocumentWriter());
058        result.add(new BusinessAdapterListWriter());
059        result.add(new SchemasWriter());
060        result.add(new SchemaWriter());
061        result.add(new DocumentTypeWriter());
062        result.add(new DocumentTypesWriter());
063        result.add(new FacetWriter());
064        result.add(new FacetsWriter());
065        result.add(new FacetsWriter());
066        result.add(new ConversionScheduledWriter());
067        result.add(new ConversionStatusWriter());
068
069        // nuxeo-core-io MarshallerRegistry service reading and writing
070        result.add(new JsonCoreIODelegate());
071
072        return result;
073    }
074}