BUG-3625 Allow replace nested composite nodes in cfg-subsystem
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / ArrayAttributeReadingStrategy.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
10
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
14 import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
15 import org.opendaylight.controller.netconf.util.xml.XmlElement;
16
17 public class ArrayAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
18
19     private final AttributeReadingStrategy innerStrategy;
20
21     /**
22      * @param attributeIfc
23      * @param innerStrategy
24      */
25     public ArrayAttributeReadingStrategy(String nullableDefault, AttributeReadingStrategy innerStrategy) {
26         super(nullableDefault);
27         this.innerStrategy = innerStrategy;
28     }
29
30     @Override
31     AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
32         List<Object> innerList = Lists.newArrayList();
33         EditStrategyType innerEditStrategy= null;
34         for (XmlElement configNode : configNodes) {
35             final AttributeConfigElement attributeConfigElement = innerStrategy.readElement(Lists.newArrayList(configNode));
36             if(attributeConfigElement.getEditStrategy().isPresent()) {
37                 // TODO this sets the last operation for the entire array
38                 innerEditStrategy = attributeConfigElement.getEditStrategy().get();
39             }
40             innerList.add(attributeConfigElement.getValue());
41         }
42         return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) :
43                 AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy);
44     }
45
46 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.