package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping;
-import java.util.Map;
-import java.util.Map.Entry;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+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;
+import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.Services;
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
-
-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 com.google.common.collect.Maps;
+import java.util.Map;
+import java.util.Map.Entry;
public class ObjectMapper extends AttributeIfcSwitchStatement<AttributeMappingStrategy<?, ? extends OpenType<?>>> {
return strategies;
}
- private AttributeMappingStrategy<?, ? extends OpenType<?>> prepareStrategy(AttributeIfc attributeIfc) {
+ public AttributeMappingStrategy<?, ? extends OpenType<?>> 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);
}
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> 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<?, ? extends OpenType<?>> innerStrategy = new SimpleAttributeMappingStrategy(
- (SimpleType<?>) arrayType.getElementOpenType());
- return new ArrayAttributeMappingStrategy(arrayType, innerStrategy);
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaSimpleAttribute(SimpleType<?> openType) {
+ return new SimpleAttributeMappingStrategy(openType);
+ }
+
+ @Override
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(ArrayType<?> openType) {
+
+ AttributeMappingStrategy<?, ? extends OpenType<?>> innerStrategy = new SimpleAttributeMappingStrategy(
+ (SimpleType<?>) openType.getElementOpenType());
+ return new ArrayAttributeMappingStrategy(openType, innerStrategy);
+ }
+
+ @Override
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaCompositeAttribute(CompositeType openType) {
+ Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
+
+ Map<String, String> 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);
}
+ private String serviceNameOfDepAttr;
+ private String namespaceOfDepAttr;
+
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
- DependencyAttribute attributeIfc) {
- String serviceName = attributeIfc.getDependency().getSie().getQName().getLocalName();
- return new ObjectNameAttributeMappingStrategy((SimpleType<?>) attributeIfc.getOpenType(), dependencyTracker,
- serviceName);
+ SimpleType<?> openType) {
+ return new ObjectNameAttributeMappingStrategy(openType, dependencyTracker,
+ serviceNameOfDepAttr, namespaceOfDepAttr);
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(TOAttribute attributeIfc) {
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(CompositeType openType) {
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
- for (Entry<String, AttributeIfc> innerAttrEntry : attributeIfc.getJmxPropertiesToTypesMap().entrySet()) {
+ Preconditions.checkState(lastAttribute instanceof TOAttribute);
+ TOAttribute lastTO = (TOAttribute) lastAttribute;
+
+ for (Entry<String, AttributeIfc> innerAttrEntry : ((TOAttribute)lastAttribute).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<?, ? extends OpenType<?>> caseListAttribute(ArrayType<?> openType) {
+ Preconditions.checkState(lastAttribute instanceof ListAttribute);
+ return new ArrayAttributeMappingStrategy(openType,
+ prepareStrategy(((ListAttribute) lastAttribute).getInnerAttribute()));
}
@Override
- protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListAttribute(ListAttribute attributeIfc) {
- return new ArrayAttributeMappingStrategy(attributeIfc.getOpenType(),
- prepareStrategy(attributeIfc.getInnerAttribute()));
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(ArrayType<?> openType) {
+ Preconditions.checkState(lastAttribute instanceof ListDependenciesAttribute);
+ return new ArrayAttributeMappingStrategy(openType, caseDependencyAttribute(SimpleType.OBJECTNAME));
}
}