2 * Copyright (c) 2014 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.controller.md.cluster.datastore.model;
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.common.Uint64;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
22 public final class CarsModel {
23 public static final QName BASE_QNAME = QName.create(
24 "urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test:cars", "2014-03-13", "cars");
26 public static final QName CARS_QNAME = QName.create(BASE_QNAME, "cars");
27 public static final QName CAR_QNAME = QName.create(CARS_QNAME, "car");
28 public static final QName CAR_NAME_QNAME = QName.create(CAR_QNAME, "name");
29 public static final QName CAR_PRICE_QNAME = QName.create(CAR_QNAME, "price");
31 public static final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(BASE_QNAME);
32 public static final YangInstanceIdentifier CAR_LIST_PATH = BASE_PATH.node(CAR_QNAME);
38 public static ContainerNode create() {
39 return Builders.containerBuilder()
40 .withNodeIdentifier(new NodeIdentifier(BASE_QNAME))
41 .withChild(Builders.mapBuilder()
42 .withNodeIdentifier(new NodeIdentifier(CAR_QNAME))
43 // Create an entry for the car altima
44 .withChild(ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "altima")
45 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "altima"))
46 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf(1000)))
48 // Create an entry for the car accord
49 .withChild(ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, "accord")
50 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, "accord"))
51 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, Uint64.valueOf("2000")))
57 public static NormalizedNode createEmptyCarsList() {
58 return newCarsNode(newCarsMapNode());
61 public static ContainerNode newCarsNode(final MapNode carsList) {
62 return Builders.containerBuilder()
63 .withNodeIdentifier(new NodeIdentifier(BASE_QNAME))
68 public static MapNode newCarsMapNode(final MapEntryNode... carEntries) {
69 var builder = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(CAR_QNAME));
70 for (MapEntryNode e : carEntries) {
74 return builder.build();
77 public static ContainerNode emptyContainer() {
78 return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BASE_QNAME)).build();
81 public static SystemMapNode newCarMapNode() {
82 return ImmutableNodes.mapNodeBuilder(CAR_QNAME).build();
85 public static MapEntryNode newCarEntry(final String name, final Uint64 price) {
86 return ImmutableNodes.mapEntryBuilder(CAR_QNAME, CAR_NAME_QNAME, name)
87 .withChild(ImmutableNodes.leafNode(CAR_NAME_QNAME, name))
88 .withChild(ImmutableNodes.leafNode(CAR_PRICE_QNAME, price)).build();
91 public static YangInstanceIdentifier newCarPath(final String name) {
92 return YangInstanceIdentifier.builder(CAR_LIST_PATH).nodeWithKey(CAR_QNAME, CAR_NAME_QNAME, name).build();