2 * Copyright (c) 2013 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
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Lists;
13 import com.google.common.collect.Maps;
14 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
15 import org.opendaylight.controller.netconf.util.xml.XmlElement;
17 import java.util.List;
19 import java.util.Map.Entry;
21 public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
23 private final Map<String, AttributeReadingStrategy> innerStrategies;
25 public CompositeAttributeReadingStrategy(String nullableDefault,
26 Map<String, AttributeReadingStrategy> innerStrategies) {
27 super(nullableDefault);
28 this.innerStrategies = innerStrategies;
32 AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
34 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
36 XmlElement complexElement = configNodes.get(0);
38 Map<String, Object> innerMap = Maps.newHashMap();
40 List<XmlElement> recognisedChildren = Lists.newArrayList();
41 for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
42 List<XmlElement> childItem = null;
43 childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
44 recognisedChildren.addAll(childItem);
46 AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);
48 innerMap.put(innerAttrEntry.getKey(), resolvedInner.getValue());
51 complexElement.checkUnrecognisedElements(recognisedChildren);
53 return AttributeConfigElement.create(getNullableDefault(), innerMap);