Disconnect RestconfSchemaServiceImpl from SchemaContextHandler
[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.handlers.SchemaContextHandler;
18 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfSchemaService;
19 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.SchemaExportContext;
20 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22
23 /**
24  * Implementation of {@link RestconfSchemaService}.
25  */
26 @Path("/")
27 public class RestconfSchemaServiceImpl implements RestconfSchemaService {
28     private final DOMSchemaService schemaService;
29     private final DOMMountPointService mountPointService;
30     private final DOMYangTextSourceProvider sourceProvider;
31
32     /**
33      * Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
34      *
35      * @param schemaService a {@link DOMSchemaService}
36      * @param mountPointService a {@link DOMMountPointService}
37      */
38     public RestconfSchemaServiceImpl(final DOMSchemaService schemaService,
39             final DOMMountPointService mountPointService) {
40         this.schemaService = requireNonNull(schemaService);
41         this.mountPointService = requireNonNull(mountPointService);
42         sourceProvider = schemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class);
43         checkArgument(sourceProvider != null, "No DOMYangTextSourceProvider available in %s", schemaService);
44     }
45
46     @Override
47     public SchemaExportContext getSchema(final String identifier) {
48         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaService.getGlobalContext(), identifier,
49             mountPointService, sourceProvider);
50     }
51 }