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