57a44d8af0ec2d11cb30f3a86393ac015bac814c
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / resolving / ObjectNameAttributeResolvingStrategy.java
1 /*
2  * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.attributes.resolving;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
14 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import javax.management.ObjectName;
19 import javax.management.openmbean.SimpleType;
20
21 public class ObjectNameAttributeResolvingStrategy extends AbstractAttributeResolvingStrategy<ObjectName, SimpleType<?>> {
22
23     private final ServiceRegistryWrapper serviceTracker;
24     private static final Logger logger = LoggerFactory.getLogger(ObjectNameAttributeResolvingStrategy.class);
25
26     ObjectNameAttributeResolvingStrategy(ServiceRegistryWrapper serviceTracker) {
27         super(SimpleType.OBJECTNAME);
28         this.serviceTracker = serviceTracker;
29     }
30
31     @Override
32     public Optional<ObjectName> parseAttribute(String attrName, Object value) {
33         if (value == null) {
34             return Optional.absent();
35         }
36
37         Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
38
39         ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = (ObjectNameAttributeMappingStrategy.MappedDependency) value;
40         String serviceName = mappedDep.getServiceName();
41         String refName = mappedDep.getRefName();
42         String namespace = mappedDep.getNamespace();
43         logger.trace("Getting service instance by service name {} : {} and ref name {}", namespace, serviceName, refName);
44
45         ObjectName on = serviceTracker.getByServiceAndRefName(namespace, serviceName, refName);
46
47         logger.debug("Attribute {} : {} parsed to type {}", attrName, value, getOpenType());
48         return Optional.of(on);
49     }
50
51 }