2 * Copyright (c) 2015, 2017 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.config.facade.xml.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.config.facade.xml.util.Util;
17 import org.opendaylight.yangtools.yang.common.QName;
19 public class ObjectNameAttributeMappingStrategy
20 extends AbstractAttributeMappingStrategy<ObjectNameAttributeMappingStrategy.MappedDependency, SimpleType<?>> {
22 private final String namespace;
24 public ObjectNameAttributeMappingStrategy(final SimpleType<?> openType, final String namespace) {
26 this.namespace = namespace;
30 public Optional<MappedDependency> mapAttribute(final Object value) {
32 return Optional.absent();
35 String expectedClass = getOpenType().getClassName();
36 String realClass = value.getClass().getName();
37 Preconditions.checkArgument(realClass.equals(expectedClass),
38 "Type mismatch, expected " + expectedClass + " but was " + realClass);
39 Util.checkType(value, ObjectName.class);
41 ObjectName on = (ObjectName) value;
43 String refName = ObjectNameUtil.getReferenceName(on);
45 // we want to use the exact service name that was configured in xml so services
46 // that are referencing it can be resolved
47 return Optional.of(new MappedDependency(namespace,
48 QName.create(ObjectNameUtil.getServiceQName(on)).getLocalName(), refName));
51 public static class MappedDependency {
52 private final String namespace;
53 private final String serviceName;
54 private final String refName;
56 public MappedDependency(final String namespace, final String serviceName, final String refName) {
57 this.serviceName = serviceName;
58 this.refName = refName;
59 this.namespace = namespace;
62 public String getServiceName() {
66 public String getRefName() {
70 public String getNamespace() {
75 public String toString() {
76 return "MappedDependency{"
77 + "namespace='" + namespace + '\''
78 + ", serviceName='" + serviceName + '\''
79 + ", refName='" + refName + '\''