X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fmapping%2Fattributes%2Fmapping%2FObjectMapper.java;h=4d984acee0206c1cce11b23f6f4f0dd1415506f8;hp=1c212e9d4b57656ae65aaca9a85d3e6699542cf7;hb=8720a3f3498bbc6fab675431f4200d26641a8ec8;hpb=545b424ba9278d7aee12b9a6173e23c1b1d39dd3 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/ObjectMapper.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/ObjectMapper.java index 1c212e9d4b..4d984acee0 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/ObjectMapper.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/ObjectMapper.java @@ -8,25 +8,23 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping; +import com.google.common.base.Preconditions; import com.google.common.collect.Maps; -import org.opendaylight.controller.config.yangjmxgenerator.attribute.*; -import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.AttributeIfcSwitchStatement; -import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services; - +import java.util.Map; +import java.util.Map.Entry; import javax.management.openmbean.ArrayType; import javax.management.openmbean.CompositeType; import javax.management.openmbean.OpenType; import javax.management.openmbean.SimpleType; -import java.util.Map; -import java.util.Map.Entry; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute; +import org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute; +import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.AttributeIfcSwitchStatement; public class ObjectMapper extends AttributeIfcSwitchStatement>> { - private final Services dependencyTracker; - - public ObjectMapper(Services depTracker) { - this.dependencyTracker = depTracker; - } public Map>> prepareMapping( Map configDefinition) { @@ -40,6 +38,12 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> prepareStrategy(AttributeIfc attributeIfc) { + + if(attributeIfc instanceof DependencyAttribute) { + serviceNameOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getLocalName(); + namespaceOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString(); + } + return switchAttribute(attributeIfc); } @@ -52,44 +56,85 @@ public class ObjectMapper extends AttributeIfcSwitchStatement> caseJavaAttribute(JavaAttribute attributeIfc) { - - if (attributeIfc.getOpenType() instanceof SimpleType) - return new SimpleAttributeMappingStrategy((SimpleType) attributeIfc.getOpenType()); - else if (attributeIfc.getOpenType() instanceof ArrayType) { - ArrayType arrayType = (ArrayType) attributeIfc.getOpenType(); - AttributeMappingStrategy> innerStrategy = new SimpleAttributeMappingStrategy( - (SimpleType) arrayType.getElementOpenType()); - return new ArrayAttributeMappingStrategy(arrayType, innerStrategy); + protected AttributeMappingStrategy> caseJavaSimpleAttribute(SimpleType openType) { + return new SimpleAttributeMappingStrategy(openType); + } + + @Override + protected AttributeMappingStrategy> caseJavaArrayAttribute(ArrayType openType) { + + AttributeMappingStrategy> innerStrategy = new SimpleAttributeMappingStrategy( + (SimpleType) openType.getElementOpenType()); + return new ArrayAttributeMappingStrategy(openType, innerStrategy); + } + + @Override + protected AttributeMappingStrategy> caseJavaCompositeAttribute(CompositeType openType) { + Map>> innerStrategies = Maps.newHashMap(); + + Map attributeMapping = Maps.newHashMap(); + + for (String innerAttributeKey : openType.keySet()) { + + innerStrategies.put(innerAttributeKey, caseJavaAttribute(openType.getType(innerAttributeKey))); + attributeMapping.put(innerAttributeKey, innerAttributeKey); } - throw new IllegalStateException(JavaAttribute.class + " can only provide open type " + SimpleType.class - + " or " + ArrayType.class); + + return new CompositeAttributeMappingStrategy(openType, innerStrategies, attributeMapping); } + @Override + protected AttributeMappingStrategy> caseJavaUnionAttribute(OpenType openType) { + Map>> innerStrategies = Maps.newHashMap(); + + Map attributeMapping = Maps.newHashMap(); + + CompositeType compositeType = (CompositeType) openType; + for (String innerAttributeKey : compositeType.keySet()) { + + innerStrategies.put(innerAttributeKey, caseJavaAttribute(compositeType.getType(innerAttributeKey))); + attributeMapping.put(innerAttributeKey, innerAttributeKey); + } + + return new UnionCompositeAttributeMappingStrategy(compositeType, innerStrategies, attributeMapping); + } + + private String serviceNameOfDepAttr; + private String namespaceOfDepAttr; + @Override protected AttributeMappingStrategy> caseDependencyAttribute( - DependencyAttribute attributeIfc) { - String serviceName = attributeIfc.getDependency().getSie().getQName().getLocalName(); - return new ObjectNameAttributeMappingStrategy((SimpleType) attributeIfc.getOpenType(), dependencyTracker, - serviceName); + SimpleType openType) { + return new ObjectNameAttributeMappingStrategy(openType, + serviceNameOfDepAttr, namespaceOfDepAttr); } @Override - protected AttributeMappingStrategy> caseTOAttribute(TOAttribute attributeIfc) { + protected AttributeMappingStrategy> caseTOAttribute(CompositeType openType) { Map>> innerStrategies = Maps.newHashMap(); - for (Entry innerAttrEntry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) { + Preconditions.checkState(getLastAttribute() instanceof TOAttribute); + TOAttribute lastTO = (TOAttribute) getLastAttribute(); + + for (Entry innerAttrEntry : ((TOAttribute)getLastAttribute()).getJmxPropertiesToTypesMap().entrySet()) { innerStrategies.put(innerAttrEntry.getKey(), prepareStrategy(innerAttrEntry.getValue())); } - return new CompositeAttributeMappingStrategy((CompositeType) attributeIfc.getOpenType(), innerStrategies, - createJmxToYangMapping(attributeIfc)); + return new CompositeAttributeMappingStrategy(openType, innerStrategies, + createJmxToYangMapping(lastTO)); + } + + @Override + protected AttributeMappingStrategy> caseListAttribute(ArrayType openType) { + Preconditions.checkState(getLastAttribute() instanceof ListAttribute); + return new ArrayAttributeMappingStrategy(openType, + prepareStrategy(((ListAttribute) getLastAttribute()).getInnerAttribute())); } @Override - protected AttributeMappingStrategy> caseListAttribute(ListAttribute attributeIfc) { - return new ArrayAttributeMappingStrategy(attributeIfc.getOpenType(), - prepareStrategy(attributeIfc.getInnerAttribute())); + protected AttributeMappingStrategy> caseListDependeciesAttribute(ArrayType openType) { + Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute); + return new ArrayAttributeMappingStrategy(openType, caseDependencyAttribute(SimpleType.OBJECTNAME)); } }