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.Optional;
12 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.AttributesConstants;
14 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy;
15 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
16 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services.ServiceInstance;
17 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import javax.management.ObjectName;
22 import javax.management.openmbean.SimpleType;
24 public class ObjectNameAttributeResolvingStrategy extends AbstractAttributeResolvingStrategy<ObjectName, SimpleType<?>> {
26 private final Services serviceTracker;
27 private static final Logger logger = LoggerFactory.getLogger(ObjectNameAttributeResolvingStrategy.class);
29 ObjectNameAttributeResolvingStrategy(Services serviceTracker) {
30 super(SimpleType.OBJECTNAME);
31 this.serviceTracker = serviceTracker;
35 public Optional<ObjectName> parseAttribute(String attrName, Object value) {
37 return Optional.absent();
40 Util.checkType(value, ObjectNameAttributeMappingStrategy.MappedDependency.class);
42 ObjectNameAttributeMappingStrategy.MappedDependency mappedDep = (ObjectNameAttributeMappingStrategy.MappedDependency) value;
43 String serviceName = mappedDep.getServiceName();
44 String refName = mappedDep.getRefName();
45 String namespace = mappedDep.getNamespace();
46 logger.trace("Getting service instance by service name {} : {} and ref name {}", namespace, serviceName, refName);
48 ServiceInstance byRefName = serviceTracker.getByServiceAndRefName(namespace, serviceName, refName);
49 ObjectName on = ObjectNameUtil.createReadOnlyModuleON(byRefName.getModuleName(), byRefName.getInstanceName());
50 on = ObjectNameUtil.createON(on.toString() + "," + AttributesConstants.REF_NAME_ON_PROPERTY_KEY + "=" + refName);
52 logger.debug("Attribute {} : {} parsed to type {}", attrName, value, getOpenType());
53 return Optional.of(on);