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