import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
+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 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 java.util.Map;
-import java.util.Map.Entry;
+import org.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver;
public class ObjectMapper extends AttributeIfcSwitchStatement<AttributeMappingStrategy<?, ? extends OpenType<?>>> {
- private final Services dependencyTracker;
-
- public ObjectMapper(Services depTracker) {
- this.dependencyTracker = depTracker;
- }
+ private EnumResolver enumResolver;
public Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> prepareMapping(
- Map<String, AttributeIfc> configDefinition) {
+ Map<String, AttributeIfc> configDefinition, EnumResolver enumResolver) {
+ this.enumResolver = Preconditions.checkNotNull(enumResolver);
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> strategies = Maps.newHashMap();
for (Entry<String, AttributeIfc> attrEntry : configDefinition.entrySet()) {
if(attributeIfc instanceof DependencyAttribute) {
serviceNameOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getLocalName();
namespaceOfDepAttr = ((DependencyAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString();
+ } else if (attributeIfc instanceof ListDependenciesAttribute) {
+ serviceNameOfDepAttr = ((ListDependenciesAttribute)attributeIfc).getDependency().getSie().getQName().getLocalName();
+ namespaceOfDepAttr = ((ListDependenciesAttribute)attributeIfc).getDependency().getSie().getQName().getNamespace().toString();
}
return switchAttribute(attributeIfc);
return new SimpleAttributeMappingStrategy(openType);
}
+ @Override
+ protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaEnumAttribute(final OpenType<?> openType) {
+ return new EnumAttributeMappingStrategy(((CompositeType) openType), enumResolver);
+ }
+
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseJavaArrayAttribute(ArrayType<?> openType) {
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseDependencyAttribute(
SimpleType<?> openType) {
- return new ObjectNameAttributeMappingStrategy(openType, dependencyTracker,
+ return new ObjectNameAttributeMappingStrategy(openType,
serviceNameOfDepAttr, namespaceOfDepAttr);
}
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseTOAttribute(CompositeType openType) {
Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> innerStrategies = Maps.newHashMap();
- Preconditions.checkState(lastAttribute instanceof TOAttribute);
- TOAttribute lastTO = (TOAttribute) lastAttribute;
+ Preconditions.checkState(getLastAttribute() instanceof TOAttribute);
+ TOAttribute lastTO = (TOAttribute) getLastAttribute();
- for (Entry<String, AttributeIfc> innerAttrEntry : ((TOAttribute)lastAttribute).getJmxPropertiesToTypesMap().entrySet()) {
+ for (Entry<String, AttributeIfc> innerAttrEntry : ((TOAttribute)getLastAttribute()).getJmxPropertiesToTypesMap().entrySet()) {
innerStrategies.put(innerAttrEntry.getKey(), prepareStrategy(innerAttrEntry.getValue()));
}
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListAttribute(ArrayType<?> openType) {
- Preconditions.checkState(lastAttribute instanceof ListAttribute);
+ Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
return new ArrayAttributeMappingStrategy(openType,
- prepareStrategy(((ListAttribute) lastAttribute).getInnerAttribute()));
+ prepareStrategy(((ListAttribute) getLastAttribute()).getInnerAttribute()));
}
@Override
protected AttributeMappingStrategy<?, ? extends OpenType<?>> caseListDependeciesAttribute(ArrayType<?> openType) {
- Preconditions.checkState(lastAttribute instanceof ListDependenciesAttribute);
+ Preconditions.checkState(getLastAttribute() instanceof ListDependenciesAttribute);
return new ArrayAttributeMappingStrategy(openType, caseDependencyAttribute(SimpleType.OBJECTNAME));
}