Merge "NPE in RaftActor#onGetOnDemandRaftStats"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / util / NodeContainerProxy.java
1 /*
2  * Copyright (c) 2014 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.sal.connect.netconf.util;
9
10 import com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import com.google.common.collect.Sets;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26 import org.opendaylight.yangtools.yang.model.api.Status;
27 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
28 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.UsesNode;
30
31 /**
32  * Simple proxy for container like schema nodes, where user provides a collection of children schema nodes
33  */
34 public final class NodeContainerProxy implements ContainerSchemaNode {
35
36     private final Map<QName, DataSchemaNode> childNodes;
37     private final QName qName;
38     private final Set<AugmentationSchema> availableAugmentations;
39
40     public NodeContainerProxy(final QName qName, final Map<QName, DataSchemaNode> childNodes, final Set<AugmentationSchema> availableAugmentations) {
41         this.availableAugmentations = availableAugmentations;
42         this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes");
43         this.qName = qName;
44     }
45
46     public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes) {
47         this(qName, asMap(childNodes), Collections.<AugmentationSchema>emptySet());
48     }
49
50     public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes, final Set<AugmentationSchema> availableAugmentations) {
51         this(qName, asMap(childNodes), availableAugmentations);
52     }
53
54     private static Map<QName, DataSchemaNode> asMap(final Collection<DataSchemaNode> childNodes) {
55         return Maps.uniqueIndex(childNodes, new Function<DataSchemaNode, QName>() {
56             @Override
57             public QName apply(final DataSchemaNode input) {
58                 return input.getQName();
59             }
60         });
61     }
62
63     @Override
64     public Set<TypeDefinition<?>> getTypeDefinitions() {
65         return Collections.emptySet();
66     }
67
68     @Override
69     public Set<DataSchemaNode> getChildNodes() {
70         return Sets.newHashSet(childNodes.values());
71     }
72
73     @Override
74     public Set<GroupingDefinition> getGroupings() {
75         return Collections.emptySet();
76     }
77
78     @Override
79     public DataSchemaNode getDataChildByName(final QName qName) {
80         return childNodes.get(qName);
81     }
82
83     @Override
84     public DataSchemaNode getDataChildByName(final String s) {
85         throw new UnsupportedOperationException();
86     }
87
88     @Override
89     public Set<UsesNode> getUses() {
90         return Collections.emptySet();
91     }
92
93     @Override
94     public boolean isPresenceContainer() {
95         throw new UnsupportedOperationException();
96     }
97
98     @Override
99     public Set<AugmentationSchema> getAvailableAugmentations() {
100         return availableAugmentations;
101     }
102
103     @Override
104     public boolean isAugmenting() {
105         throw new UnsupportedOperationException();
106     }
107
108     @Override
109     public boolean isAddedByUses() {
110         throw new UnsupportedOperationException();
111     }
112
113     @Override
114     public boolean isConfiguration() {
115         throw new UnsupportedOperationException();
116     }
117
118     @Override
119     public ConstraintDefinition getConstraints() {
120         throw new UnsupportedOperationException();
121     }
122
123     @Override
124     public QName getQName() {
125         return qName;
126     }
127
128     @Override
129     public SchemaPath getPath() {
130         throw new UnsupportedOperationException();
131     }
132
133     @Override
134     public String getDescription() {
135         throw new UnsupportedOperationException();
136     }
137
138     @Override
139     public String getReference() {
140         throw new UnsupportedOperationException();
141     }
142
143     @Override
144     public Status getStatus() {
145         throw new UnsupportedOperationException();
146     }
147
148     @Override
149     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
150         return Collections.emptyList();
151     }
152 }

©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.