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.mapping;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
14 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
16 import javax.management.ObjectName;
17 import javax.management.openmbean.SimpleType;
19 public class ObjectNameAttributeMappingStrategy extends
20 AbstractAttributeMappingStrategy<ObjectNameAttributeMappingStrategy.MappedDependency, SimpleType<?>> {
22 private final Services tracker;
23 private final String serviceName;
25 public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, Services dependencyTracker, String serviceName) {
27 this.tracker = dependencyTracker;
28 this.serviceName = serviceName;
32 public Optional<MappedDependency> mapAttribute(Object value) {
34 return Optional.absent();
36 String expectedClass = getOpenType().getClassName();
37 String realClass = value.getClass().getName();
38 Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass
39 + " but was " + realClass);
40 Util.checkType(value, ObjectName.class);
42 ObjectName on = (ObjectName) value;
43 String refName = tracker.addServiceEntry(serviceName, on);
45 return Optional.of(new MappedDependency(serviceName, refName));
48 public static class MappedDependency {
49 private final String serviceName, refName;
51 public MappedDependency(String serviceName, String refName) {
52 this.serviceName = serviceName;
53 this.refName = refName;
56 public String getServiceName() {
60 public String getRefName() {
65 public String toString() {
66 final StringBuffer sb = new StringBuffer("MappedDependency{");
67 sb.append("serviceName='").append(serviceName).append('\'');
68 sb.append(", refName='").append(refName).append('\'');