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;
24 private final String namespace;
26 public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, Services dependencyTracker, String serviceName, String namespace) {
28 this.tracker = dependencyTracker;
29 this.serviceName = serviceName;
30 this.namespace = namespace;
34 public Optional<MappedDependency> mapAttribute(Object value) {
36 return Optional.absent();
38 String expectedClass = getOpenType().getClassName();
39 String realClass = value.getClass().getName();
40 Preconditions.checkArgument(realClass.equals(expectedClass), "Type mismatch, expected " + expectedClass
41 + " but was " + realClass);
42 Util.checkType(value, ObjectName.class);
44 ObjectName on = (ObjectName) value;
45 String refName = tracker.addServiceEntry(namespace, serviceName, on);
47 return Optional.of(new MappedDependency(namespace, serviceName, refName));
50 public static class MappedDependency {
51 private final String namespace, serviceName, refName;
53 public MappedDependency(String namespace, String serviceName, String refName) {
54 this.serviceName = serviceName;
55 this.refName = refName;
56 this.namespace = namespace;
59 public String getServiceName() {
63 public String getRefName() {
67 public String getNamespace() {
72 public String toString() {
73 final StringBuffer sb = new StringBuffer("MappedDependency{");
74 sb.append("namespace='").append(namespace).append('\'');
75 sb.append(", serviceName='").append(serviceName).append('\'');
76 sb.append(", refName='").append(refName).append('\'');