Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / fromxml / ArrayAttributeReadingStrategy.java
1 /*
2  * Copyright (c) 2015, 2017 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.config.facade.xml.mapping.attributes.fromxml;
10
11 import com.google.common.collect.Lists;
12 import java.util.List;
13 import org.opendaylight.controller.config.facade.xml.strategy.EditStrategyType;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
15 import org.opendaylight.controller.config.util.xml.XmlElement;
16
17 public class ArrayAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
18
19     private final AttributeReadingStrategy innerStrategy;
20
21     public ArrayAttributeReadingStrategy(final String nullableDefault, final AttributeReadingStrategy innerStrategy) {
22         super(nullableDefault);
23         this.innerStrategy = innerStrategy;
24     }
25
26     @Override
27     AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
28         List<Object> innerList = Lists.newArrayList();
29         EditStrategyType innerEditStrategy = null;
30         for (XmlElement configNode : configNodes) {
31             final AttributeConfigElement attributeConfigElement = innerStrategy
32                     .readElement(Lists.newArrayList(configNode));
33             if (attributeConfigElement.getEditStrategy().isPresent()) {
34                 // TODO this sets the last operation for the entire array
35                 innerEditStrategy = attributeConfigElement.getEditStrategy().get();
36             }
37             innerList.add(attributeConfigElement.getValue());
38         }
39         return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList)
40                 : AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy);
41     }
42
43 }