bafb33b88d750e397b7988fcf6a4ed09df223bc2
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / mapping / EnumAttributeMappingStrategy.java
1 /*
2  * Copyright (c) 2015 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.mapping;
10
11 import com.google.common.base.Optional;
12 import javax.management.openmbean.CompositeType;
13 import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
14
15 public class EnumAttributeMappingStrategy extends AbstractAttributeMappingStrategy<String, CompositeType> {
16
17     private final EnumResolver enumResolver;
18
19     public EnumAttributeMappingStrategy(CompositeType openType, final EnumResolver enumResolver) {
20         super(openType);
21         this.enumResolver = enumResolver;
22     }
23
24     @Override
25     public Optional<String> mapAttribute(Object value) {
26         if (value == null){
27             return Optional.absent();
28         }
29
30         String expectedClass = getOpenType().getTypeName();
31         return Optional.of(enumResolver.toYang(expectedClass, value.toString()));
32     }
33
34 }