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 javax.management.ObjectName;
14 import javax.management.openmbean.SimpleType;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
16 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
18 public class ObjectNameAttributeMappingStrategy extends
19 AbstractAttributeMappingStrategy<ObjectNameAttributeMappingStrategy.MappedDependency, SimpleType<?>> {
21 private final String serviceName;
22 private final String namespace;
24 public ObjectNameAttributeMappingStrategy(SimpleType<?> openType, String serviceName, String namespace) {
26 this.serviceName = serviceName;
27 this.namespace = namespace;
31 public Optional<MappedDependency> mapAttribute(Object value) {
33 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;
44 String refName = ObjectNameUtil.getReferenceName(on);
46 return Optional.of(new MappedDependency(namespace, serviceName, refName));
49 public static class MappedDependency {
50 private final String namespace, serviceName, refName;
52 public MappedDependency(String namespace, String serviceName, String refName) {
53 this.serviceName = serviceName;
54 this.refName = refName;
55 this.namespace = namespace;
58 public String getServiceName() {
62 public String getRefName() {
66 public String getNamespace() {
71 public String toString() {
72 final StringBuffer sb = new StringBuffer("MappedDependency{");
73 sb.append("namespace='").append(namespace).append('\'');
74 sb.append(", serviceName='").append(serviceName).append('\'');
75 sb.append(", refName='").append(refName).append('\'');