Add DatabindContext and its wiring
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfSchemaServiceImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import javax.ws.rs.Path;
14 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
15 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
16 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
17 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
18 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
19 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
20
21 /**
22  * Implementation of {@link RestconfSchemaService}.
23  */
24 @Path("/")
25 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
26     private final DOMSchemaService schemaService;
27     private final DOMMountPointService mountPointService;
28     private final DOMYangTextSourceProvider sourceProvider;
29
30     /**
31      * Default constructor.
32      *
33      * @param schemaService a {@link DOMSchemaService}
34      * @param mountPointService a {@link DOMMountPointService}
35      */
36     public RestconfSchemaServiceImpl(final DOMSchemaService schemaService,
37             final DOMMountPointService mountPointService) {
38         this.schemaService = requireNonNull(schemaService);
39         this.mountPointService = requireNonNull(mountPointService);
40         sourceProvider = schemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class);
41         checkArgument(sourceProvider != null, "No DOMYangTextSourceProvider available in %s", schemaService);
42     }
43
44     @Override
45     public SchemaExportContext getSchema(final String identifier) {
46         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaService.getGlobalContext(), identifier,
47             mountPointService, sourceProvider);
48     }
49 }