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 static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.List;
15 import javax.ws.rs.core.Application;
16 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
17 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
18 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
19 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyWriter;
20 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
21 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyWriter;
22 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YangSchemaExportBodyWriter;
23 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YinSchemaExportBodyWriter;
24 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
25 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonPatchBodyReader;
26 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonPatchStatusBodyWriter;
27 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlPatchBodyReader;
28 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlPatchStatusBodyWriter;
31 * Abstract Restconf Application.
33 abstract class AbstractRestconfApplication extends Application {
34 private final SchemaContextHandler schemaContextHandler;
35 private final DOMMountPointService mountPointService;
36 private final List<Object> services;
38 AbstractRestconfApplication(final SchemaContextHandler schemaContextHandler,
39 final DOMMountPointService mountPointService, final List<Object> services) {
40 this.schemaContextHandler = requireNonNull(schemaContextHandler);
41 this.mountPointService = requireNonNull(mountPointService);
42 this.services = requireNonNull(services);
46 public final Set<Class<?>> getClasses() {
48 JsonNormalizedNodeBodyWriter.class, XmlNormalizedNodeBodyWriter.class,
49 YinSchemaExportBodyWriter.class, YangSchemaExportBodyWriter.class,
50 JsonPatchStatusBodyWriter.class, XmlPatchStatusBodyWriter.class);
54 public final Set<Object> getSingletons() {
55 return ImmutableSet.<Object>builderWithExpectedSize(services.size() + 5)
57 .add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService))
58 .add(new JsonPatchBodyReader(schemaContextHandler, mountPointService))
59 .add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointService))
60 .add(new XmlPatchBodyReader(schemaContextHandler, mountPointService))
61 .add(new RestconfDocumentedExceptionMapper(schemaContextHandler))