Merge "Bug 809: Enhancements to the toaster example"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / resolving / CompositeAttributeResolvingStrategy.java
index c477821051b08d03288d129fc29c1aaddd32eef6..83ebf65d7fb71c1e5791dcfac416e4097a94f675 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attri
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,7 +22,7 @@ import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.OpenType;
 import java.util.Map;
 
-final class CompositeAttributeResolvingStrategy extends
+class CompositeAttributeResolvingStrategy extends
         AbstractAttributeResolvingStrategy<CompositeDataSupport, CompositeType> {
     private final Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> innerTypes;
     private final Map<String, String> yangToJavaAttrMapping;
@@ -41,7 +42,7 @@ final class CompositeAttributeResolvingStrategy extends
     }
 
     @Override
-    public Optional<CompositeDataSupport> parseAttribute(String attrName, Object value) {
+    public Optional<CompositeDataSupport> parseAttribute(String attrName, Object value) throws NetconfDocumentedException {
 
         if (value == null) {
             return Optional.absent();
@@ -49,6 +50,7 @@ final class CompositeAttributeResolvingStrategy extends
 
         Util.checkType(value, Map.class);
         Map<?, ?> valueMap = (Map<?, ?>) value;
+        valueMap = preprocessValueMap(valueMap);
 
         Map<String, Object> items = Maps.newHashMap();
         Map<String, OpenType<?>> openTypes = Maps.newHashMap();
@@ -74,7 +76,7 @@ final class CompositeAttributeResolvingStrategy extends
         try {
             parsedValue = new CompositeDataSupport(getOpenType(), items);
         } catch (OpenDataException e) {
-            throw new RuntimeException("An error occured during restoration of composite type " + this
+            throw new IllegalStateException("An error occured during restoration of composite type " + this
                     + " for attribute " + attrName + " from value " + value, e);
         }
 
@@ -82,4 +84,8 @@ final class CompositeAttributeResolvingStrategy extends
 
         return Optional.of(parsedValue);
     }
+
+    protected Map<?, ?> preprocessValueMap(Map<?, ?> valueMap) {
+        return valueMap;
+    }
 }