Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / resolving / UnionCompositeAttributeResolvingStrategy.java
1 /*
2  * Copyright (c) 2015, 2017 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.resolving;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Maps;
13 import java.util.Map;
14 import javax.management.openmbean.CompositeType;
15 import javax.management.openmbean.OpenType;
16 import org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute;
17
18 final class UnionCompositeAttributeResolvingStrategy extends CompositeAttributeResolvingStrategy {
19
20     UnionCompositeAttributeResolvingStrategy(
21             final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes,
22             final CompositeType openType, final Map<String, String> yangToJavaAttrMapping) {
23         super(innerTypes, openType, yangToJavaAttrMapping);
24     }
25
26     @Override
27     protected Map<String, Object> preprocessValueMap(final Map<?, ?> valueMap) {
28         CompositeType openType = getOpenType();
29
30         Preconditions.checkArgument(
31                 valueMap.size() == 1 && valueMap.containsKey(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION),
32                 "Unexpected structure of incoming map, expecting one element under %s, but was %s",
33                 JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION, valueMap);
34
35         Map<String, Object> newMap = Maps.newHashMap();
36
37         for (String key : openType.keySet()) {
38             if (openType.getDescription(key).equals(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION)) {
39                 newMap.put(key, valueMap.get(JavaAttribute.DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION));
40             } else {
41                 newMap.put(key, null);
42             }
43         }
44         return newMap;
45     }
46 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.