2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.rests.services.impl;
10 import static java.util.Objects.requireNonNull;
12 import javax.ws.rs.Path;
13 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
14 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
15 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
16 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
17 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
25 public class RestconfImpl implements RestconfService {
26 private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern();
28 private final SchemaContextHandler schemaContextHandler;
30 public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
31 this.schemaContextHandler = requireNonNull(schemaContextHandler);
35 public NormalizedNodePayload getLibraryVersion() {
36 final EffectiveModelContext context = schemaContextHandler.get();
38 final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
39 // FIXME: use rc:data instantiation once the stack supports it
40 stack.enterGrouping(Restconf.QNAME);
41 stack.enterDataTree(Restconf.QNAME);
42 stack.enterDataTree(YANG_LIBRARY_VERSION);
44 return NormalizedNodePayload.of(InstanceIdentifierContext.ofStack(stack),
45 ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, IetfYangLibrary.REVISION.toString()));