a73154f7258cd72ec3b84fd883ffb8593f80f418
[netconf.git] / restconf / restconf-nb-rfc8040 / 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 java.util.Objects.requireNonNull;
11
12 import javax.ws.rs.Path;
13 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
14 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
15 import org.opendaylight.restconf.common.schema.SchemaExportContext;
16 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
17 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
18 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 /**
22  * Implementation of {@link RestconfSchemaService}.
23  */
24 @Path("/")
25 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
26     private final SchemaContextHandler schemaContextHandler;
27     private final DOMMountPointService mountPointService;
28     private final DOMYangTextSourceProvider sourceProvider;
29
30     /**
31      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
32      *
33      * @param schemaContextHandler handling schema context
34      * @param mountPointService dom mount point service
35      */
36     public RestconfSchemaServiceImpl(final SchemaContextHandler schemaContextHandler,
37                                      final DOMMountPointService mountPointService,
38                                      final DOMYangTextSourceProvider sourceProvider) {
39         this.schemaContextHandler = requireNonNull(schemaContextHandler);
40         this.mountPointService = requireNonNull(mountPointService);
41         this.sourceProvider = requireNonNull(sourceProvider);
42     }
43
44     @Override
45     public SchemaExportContext getSchema(final String identifier) {
46         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextHandler.get(), identifier,
47             mountPointService, sourceProvider);
48     }
49 }