2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.v3po.data.impl;
19 import com.google.common.base.Preconditions;
20 import java.util.Collection;
21 import java.util.HashMap;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
29 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Utility class for various operations on DataTree.
36 final class DataTreeUtils {
37 private static final Logger LOG = LoggerFactory.getLogger(DataTreeUtils.class);
39 private DataTreeUtils() {
40 throw new UnsupportedOperationException("Can't instantiate util class");
44 * Translates children of supplied YANG ContainerNode into Binding data.
46 * @param parent ContainerNode representing data
47 * @param serializer service for serialization between Java Binding Data representation and NormalizedNode
49 * @return NormalizedNode representation of parent's node children
51 static Map<InstanceIdentifier<?>, DataObject> childrenFromNormalized(@Nonnull final DataContainerNode parent,
52 @Nonnull final BindingNormalizedNodeSerializer serializer) {
54 Preconditions.checkNotNull(parent, "parent node should not be null");
55 Preconditions.checkNotNull(serializer, "serializer should not be null");
57 final Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
59 final Collection<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> children =
62 for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : children) {
63 final YangInstanceIdentifier.PathArgument pathArgument = child.getIdentifier();
64 final YangInstanceIdentifier identifier = YangInstanceIdentifier.create(pathArgument);
65 LOG.debug("DataTreeUtils.childrenFromNormalized() child={}, pathArgument={}, identifier={}", child,
66 pathArgument, identifier);
68 final Map.Entry<InstanceIdentifier<?>, DataObject> entry = serializer.fromNormalizedNode(identifier, child);
70 map.put(entry.getKey(), entry.getValue());