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;
12 import java.util.Map.Entry;
14 import javax.management.openmbean.ArrayType;
15 import javax.management.openmbean.CompositeType;
16 import javax.management.openmbean.OpenType;
17 import javax.management.openmbean.SimpleType;
19 import org.opendaylight.controller.config.yangjmxgenerator.attribute.*;
20 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.AttributeIfcSwitchStatement;
21 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
23 import com.google.common.collect.Maps;
25 public class ObjectMapper extends AttributeIfcSwitchStatement<AttributeMappingStrategy<?, ? extends OpenType<?>>> {
27 private final Services dependencyTracker;
29 public ObjectMapper(Services depTracker) {
30 this.dependencyTracker = depTracker;
33 public Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> prepareMapping(
34 Map<String, AttributeIfc> configDefinition) {
35 Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> strategies = Maps.newHashMap();
37 for (Entry<String, AttributeIfc> attrEntry : configDefinition.entrySet()) {
38 strategies.put(attrEntry.getKey(), prepareStrategy(attrEntry.getValue()));
44 private AttributeMappingStrategy<?, ? extends OpenType<?>> prepareStrategy(AttributeIfc attributeIfc) {
45 return switchAttribute(attributeIfc);
48 private Map<String, String> createJmxToYangMapping(TOAttribute attributeIfc) {
49 Map<String, String> retVal = Maps.newHashMap();
50 for (Entry<String, AttributeIfc> entry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) {
51 retVal.put(entry.getKey(), (entry.getValue()).getAttributeYangName());
57 protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaAttribute(JavaAttribute attributeIfc) {
59 if (attributeIfc.getOpenType() instanceof SimpleType<?>)
60 return new SimpleAttributeMappingStrategy((SimpleType<?>) attributeIfc.getOpenType());
61 else if (attributeIfc.getOpenType() instanceof ArrayType<?>) {
62 ArrayType<?> arrayType = (ArrayType<?>) attributeIfc.getOpenType();
63 AttributeMappingStrategy<?, ? extends OpenType<?>> innerStrategy = new SimpleAttributeMappingStrategy(
64 (SimpleType<?>) arrayType.getElementOpenType());
65 return new ArrayAttributeMappingStrategy(arrayType, innerStrategy);
67 throw new IllegalStateException(JavaAttribute.class + " can only provide open type " + SimpleType.class
68 + " or " + ArrayType.class);
72 protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
73 DependencyAttribute attributeIfc) {
74 String serviceName = attributeIfc.getDependency().getSie().getQName().getLocalName();
75 return new ObjectNameAttributeMappingStrategy((SimpleType<?>) attributeIfc.getOpenType(), dependencyTracker,
80 protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(TOAttribute attributeIfc) {
81 Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
83 for (Entry<String, AttributeIfc> innerAttrEntry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) {
84 innerStrategies.put(innerAttrEntry.getKey(), prepareStrategy(innerAttrEntry.getValue()));
87 return new CompositeAttributeMappingStrategy((CompositeType) attributeIfc.getOpenType(), innerStrategies,
88 createJmxToYangMapping(attributeIfc));
92 protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListAttribute(ListAttribute attributeIfc) {
93 return new ArrayAttributeMappingStrategy(attributeIfc.getOpenType(),
94 prepareStrategy(attributeIfc.getInnerAttribute()));