Merge "Add sal-akka-raft test-jar dependency to sal-distributed-store pom"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / LazySerializedContainerNode.java
1 /*
2  * Copyright (c) 2015 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.controller.md.sal.binding.impl;
9
10 import com.google.common.base.Optional;
11 import java.util.Collection;
12 import java.util.Map;
13 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
20
21 /**
22  *
23  * FIXME: Should be this moved to binding-data-codec?
24  *
25  */
26 class LazySerializedContainerNode implements ContainerNode {
27
28     private final NodeIdentifier identifier;
29     private final DataObject bindingData;
30
31     private BindingNormalizedNodeCodecRegistry registry;
32     private ContainerNode domData;
33
34     LazySerializedContainerNode(QName identifier, DataObject binding,
35             BindingNormalizedNodeCodecRegistry registry) {
36         this.identifier = new NodeIdentifier(identifier);
37         this.bindingData = binding;
38         this.registry = registry;
39         this.domData = null;
40     }
41
42     @Override
43     public Map<QName, String> getAttributes() {
44         return delegate().getAttributes();
45     }
46
47     private ContainerNode delegate() {
48         if(domData == null) {
49             domData = registry.toNormalizedNodeRpcData(bindingData);
50             registry = null;
51         }
52         return domData;
53     }
54
55     @Override
56     public QName getNodeType() {
57         return delegate().getNodeType();
58     }
59
60     @Override
61     public Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
62         return delegate().getValue();
63     }
64
65     @Override
66     public NodeIdentifier getIdentifier() {
67         return identifier;
68     }
69
70     @Override
71     public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(PathArgument child) {
72         return delegate().getChild(child);
73     }
74
75     @Override
76     public Object getAttributeValue(QName name) {
77         return delegate().getAttributeValue(name);
78     }
79
80     public DataObject bindingData() {
81         return bindingData;
82     }
83
84 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.