2 * Copyright (c) 2020 Lumina Networks, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashSet;
13 import javax.ws.rs.core.Application;
14 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
15 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
16 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
17 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeJsonBodyWriter;
18 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeXmlBodyWriter;
19 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
20 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
21 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonToPatchBodyReader;
22 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchJsonBodyWriter;
23 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchXmlBodyWriter;
24 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
25 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYangBodyWriter;
26 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
27 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesNotifWrapper;
28 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
31 * Abstract Restconf Application.
33 * @param <T> {@link ServicesWrapper} or {@link ServicesNotifWrapper} implementation
35 public abstract class AbstractRestconfApplication<T> extends Application {
36 private final SchemaContextHandler schemaContextHandler;
37 private final DOMMountPointServiceHandler mountPointServiceHandler;
38 private final T servicesWrapper;
40 public AbstractRestconfApplication(final SchemaContextHandler schemaContextHandler,
41 final DOMMountPointServiceHandler mountPointServiceHandler, final T servicesNotifWrapper) {
42 this.schemaContextHandler = schemaContextHandler;
43 this.mountPointServiceHandler = mountPointServiceHandler;
44 this.servicesWrapper = servicesNotifWrapper;
48 public Set<Class<?>> getClasses() {
49 return ImmutableSet.<Class<?>>builder()
50 .add(NormalizedNodeJsonBodyWriter.class).add(NormalizedNodeXmlBodyWriter.class)
51 .add(SchemaExportContentYinBodyWriter.class).add(SchemaExportContentYangBodyWriter.class)
52 .add(PatchJsonBodyWriter.class).add(PatchXmlBodyWriter.class)
57 public Set<Object> getSingletons() {
58 final Set<Object> singletons = new HashSet<>();
59 singletons.add(servicesWrapper);
60 singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
61 singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
62 singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
63 singletons.add(new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
64 singletons.add(new RestconfDocumentedExceptionMapper(schemaContextHandler));