config-manager-facade-xml: final parameters
[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 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.readElement(Lists.newArrayList(configNode));
32             if(attributeConfigElement.getEditStrategy().isPresent()) {
33                 // TODO this sets the last operation for the entire array
34                 innerEditStrategy = attributeConfigElement.getEditStrategy().get();
35             }
36             innerList.add(attributeConfigElement.getValue());
37         }
38         return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) :
39                 AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy);
40     }
41
42 }