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.sal.dom.store.impl;
10 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.TreeNodeUtils;
12 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import com.google.common.base.Optional;
20 class DataAndMetadataSnapshot {
22 private final StoreMetadataNode metadataTree;
23 private final Optional<SchemaContext> schemaContext;
28 private DataAndMetadataSnapshot(final StoreMetadataNode metadataTree, final Optional<SchemaContext> schemaCtx) {
29 this.metadataTree = metadataTree;
30 this.schemaContext = schemaCtx;
33 public static Builder builder() {
37 public static DataAndMetadataSnapshot createEmpty(final NodeIdentifier rootNode) {
38 NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(rootNode).build();
39 StoreMetadataNode metadata = StoreMetadataNode.builder()
42 return new DataAndMetadataSnapshot(metadata,Optional.<SchemaContext>absent());
45 public static DataAndMetadataSnapshot createEmpty(final SchemaContext ctx) {
46 NodeIdentifier rootNodeIdentifier = new NodeIdentifier(ctx.getQName());
47 NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(rootNodeIdentifier).build();
48 StoreMetadataNode metadata = StoreMetadataNode.builder()
51 return new DataAndMetadataSnapshot(metadata, Optional.of(ctx));
54 public Optional<SchemaContext> getSchemaContext() {
58 public NormalizedNode<?, ?> getDataTree() {
59 return metadataTree.getData();
62 public StoreMetadataNode getMetadataTree() {
66 public Optional<StoreMetadataNode> read(final InstanceIdentifier path) {
67 return TreeNodeUtils.findNode(metadataTree, path);
70 public static class Builder {
71 private NormalizedNode<?, ?> dataTree;
72 private StoreMetadataNode metadataTree;
73 private SchemaContext schemaContext;
75 public NormalizedNode<?, ?> getDataTree() {
79 public Builder setMetadataTree(final StoreMetadataNode metadataTree) {
80 this.metadataTree = metadataTree;
84 public Builder setSchemaContext(final SchemaContext schemaContext) {
85 this.schemaContext = schemaContext;
89 public DataAndMetadataSnapshot build() {
90 return new DataAndMetadataSnapshot(metadataTree, Optional.fromNullable(schemaContext));