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.config.yangjmxgenerator.attribute.AttributeIfc;
15 import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute;
16 import org.opendaylight.controller.netconf.util.xml.XmlElement;
18 import java.util.List;
20 import java.util.Map.Entry;
22 public class CompositeAttributeReadingStrategy extends AbstractAttributeReadingStrategy<TOAttribute> {
24 private final Map<String, AttributeReadingStrategy> innerStrategies;
26 public CompositeAttributeReadingStrategy(TOAttribute attributeIfc,
27 Map<String, AttributeReadingStrategy> innerStrategies) {
29 this.innerStrategies = innerStrategies;
33 AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
35 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s", configNodes);
37 XmlElement complexElement = configNodes.get(0);
39 Map<String, Object> innerMap = Maps.newHashMap();
41 Map<String, AttributeIfc> inner = getAttributeIfc().getYangPropertiesToTypesMap();
43 List<XmlElement> recognisedChildren = Lists.newArrayList();
44 for (Entry<String, AttributeIfc> innerAttrEntry : inner.entrySet()) {
45 List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
46 recognisedChildren.addAll(childItem);
48 AttributeConfigElement resolvedInner = innerStrategies.get(innerAttrEntry.getKey()).readElement(childItem);
50 innerMap.put(innerAttrEntry.getKey(), resolvedInner.getValue());
53 complexElement.checkUnrecognisedElements(recognisedChildren);
55 return AttributeConfigElement.create(getAttributeIfc(), innerMap);