Merge "Resolve Bug:748 - Remove test resources from netconf-impl."
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / resolving / ArrayAttributeResolvingStrategy.java
index adee8bec58086a02a92835deea84c578a8c94cd6..f0d7960085f21bd5e4a220797d648521c93f51d8 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving;
 
 import com.google.common.base.Optional;
+import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,7 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt
     }
 
     @Override
-    public Optional<Object> parseAttribute(String attrName, Object value) {
+    public Optional<Object> parseAttribute(String attrName, Object value) throws NetconfDocumentedException {
         if (value == null) {
             return Optional.absent();
         }
@@ -45,31 +46,31 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt
 
         if (innerTypeResolvingStrategy.getOpenType() instanceof CompositeType) {
             innerTypeClass = CompositeDataSupport.class;
-        } else
+        } else {
             try {
                 innerTypeClass = Class.forName(getOpenType().getElementOpenType().getClassName());
             } catch (ClassNotFoundException e) {
-                throw new RuntimeException("Unable to locate class for "
+                throw new IllegalStateException("Unable to locate class for "
                         + getOpenType().getElementOpenType().getClassName(), e);
             }
+        }
 
         Object parsedArray = null;
 
         if (getOpenType().isPrimitiveArray()) {
             Class<?> primitiveType = getPrimitiveType(innerTypeClass);
             parsedArray = Array.newInstance(primitiveType, valueList.size());
-        } else
+        } else {
             parsedArray = Array.newInstance(innerTypeClass, valueList.size());
+        }
 
         int i = 0;
         for (Object innerValue : valueList) {
             Optional<?> parsedElement = innerTypeResolvingStrategy.parseAttribute(attrName + "_" + i, innerValue);
-
-            if (!parsedElement.isPresent())
+            if (!parsedElement.isPresent()){
                 continue;
-
+            }
             Array.set(parsedArray, i, parsedElement.get());
-            // parsedArray[i] = parsedElement.get();
             i++;
         }
 
@@ -94,7 +95,7 @@ final class ArrayAttributeResolvingStrategy extends AbstractAttributeResolvingSt
         try {
             return (Class<?>) innerTypeClass.getField("TYPE").get(null);
         } catch (Exception e) {
-            throw new RuntimeException("Unable to determine primitive type to " + innerTypeClass);
+            throw new IllegalStateException("Unable to determine primitive type to " + innerTypeClass);
         }
     }