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.util.xml.XmlElement;
16 import java.util.List;
18 import java.util.Map.Entry;
20 public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
22 private final Map<String, AttributeReadingStrategy> innerStrategies;
24 public CompositeAttributeReadingStrategy(String nullableDefault,
25 Map<String, AttributeReadingStrategy> innerStrategies) {
26 super(nullableDefault);
27 this.innerStrategies = innerStrategies;
31 AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
33 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
35 XmlElement complexElement = configNodes.get(0);
37 Map<String, Object> innerMap = Maps.newHashMap();
39 List<XmlElement> recognisedChildren = Lists.newArrayList();
40 for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
41 List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
42 recognisedChildren.addAll(childItem);
44 AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);
46 innerMap.put(innerAttrEntry.getKey(), resolvedInner.getValue());
49 complexElement.checkUnrecognisedElements(recognisedChildren);
51 return AttributeConfigElement.create(getNullableDefault(), innerMap);