2 * Copyright (c) 2015, 2017 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.mapping;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.Lists;
14 import java.lang.reflect.Array;
15 import java.util.List;
16 import javax.management.openmbean.ArrayType;
17 import javax.management.openmbean.OpenType;
19 public class ArrayAttributeMappingStrategy extends AbstractAttributeMappingStrategy<List<Object>, ArrayType<?>> {
21 private final AttributeMappingStrategy<?, ? extends OpenType<?>> innerElementStrategy;
23 public ArrayAttributeMappingStrategy(final ArrayType<?> arrayType,
24 final AttributeMappingStrategy<?, ? extends OpenType<?>> innerElementStrategy) {
26 this.innerElementStrategy = innerElementStrategy;
30 public Optional<List<Object>> mapAttribute(final Object value) {
32 return Optional.absent();
35 Preconditions.checkArgument(value.getClass().isArray(), "Value has to be instanceof Array ");
37 List<Object> retVal = Lists.newArrayList();
39 for (int i = 0; i < Array.getLength(value); i++) {
40 Object innerValue = Array.get(value, i);
41 Optional<?> mapAttribute = innerElementStrategy.mapAttribute(innerValue);
43 if (mapAttribute.isPresent()) {
44 retVal.add(mapAttribute.get());
47 return Optional.of(retVal);