442c504cce28ebc96b26e7bba589563ee3bef1d4
[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 org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.util.xml.XmlElement;
14
15 import java.util.List;
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         for (int i = 0; i < configNodes.size(); i++) {
34             innerList.add(innerStrategy.readElement(Lists.newArrayList(configNodes.get(i))).getValue());
35         }
36         return AttributeConfigElement.create(getNullableDefault(), innerList);
37     }
38
39 }