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;
15 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
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 {
24 private final Map<String, AttributeReadingStrategy> innerStrategies;
26 public CompositeAttributeReadingStrategy(String nullableDefault,
27 Map<String, AttributeReadingStrategy> innerStrategies) {
28 super(nullableDefault);
29 this.innerStrategies = innerStrategies;
33 AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
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 List<XmlElement> recognisedChildren = Lists.newArrayList();
42 for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
43 List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(
44 innerAttrEntry.getKey());
45 recognisedChildren.addAll(childItem);
47 AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);
49 Object value = resolvedInner.getValue();
51 value = resolvedInner.getDefaultValue();
54 innerMap.put(innerAttrEntry.getKey(), value);
57 complexElement.checkUnrecognisedElements(recognisedChildren);
59 return AttributeConfigElement.create(getNullableDefault(), innerMap);