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.resolving;
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
15 import javax.management.openmbean.CompositeType;
16 import javax.management.openmbean.OpenType;
19 final class UnionCompositeAttributeResolvingStrategy extends CompositeAttributeResolvingStrategy {
21 UnionCompositeAttributeResolvingStrategy(Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
22 CompositeType openType, Map<String, String> yangToJavaAttrMapping) {
23 super(innerTypes, openType, yangToJavaAttrMapping);
26 protected Map<String, Object> preprocessValueMap(Map<?, ?> valueMap) {
27 CompositeType openType = getOpenType();
29 Preconditions.checkArgument(
30 valueMap.size() == 1 && valueMap.containsKey(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION),
31 "Unexpected structure of incoming map, expecting one element under %s, but was %s",
32 JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION, valueMap);
34 Map<String, Object> newMap = Maps.newHashMap();
36 for (String key : openType.keySet()) {
37 if (openType.getDescription(key).equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION))
38 newMap.put(key, valueMap.get(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION));
40 newMap.put(key, null);