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