2 * Copyright (c) 2015 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.config.facade.xml.mapping.attributes.fromxml;
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;
17 public class ArrayAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
19 private final AttributeReadingStrategy innerStrategy;
21 public ArrayAttributeReadingStrategy(String nullableDefault, AttributeReadingStrategy innerStrategy) {
22 super(nullableDefault);
23 this.innerStrategy = innerStrategy;
27 AttributeConfigElement readElementHook(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();
36 innerList.add(attributeConfigElement.getValue());
38 return innerEditStrategy == null ? AttributeConfigElement.create(getNullableDefault(), innerList) :
39 AttributeConfigElement.create(getNullableDefault(), innerList, innerEditStrategy);