BUG-3625 Allow replace nested composite nodes in cfg-subsystem
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / AttributeConfigElement.java
index dcc2fa15439b01ecd15eca5144f15eaa3a77086b..fac1b358ce52365850bd05c861a8c751bc9c6503 100644 (file)
@@ -9,26 +9,28 @@
 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
 
 import com.google.common.base.Optional;
+import javax.management.openmbean.OpenType;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.resolving.AttributeResolvingStrategy;
-
-import javax.management.openmbean.OpenType;
+import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditStrategyType;
 
 /**
  * Parsed xml element containing configuration for one attribute of an instance
  * of some module. Contains default value extracted from yang file.
  */
 public class AttributeConfigElement {
-    private final Object dafaultValue;
+    private final Object defaultValue;
     private final Object value;
+    private final Optional<EditStrategyType> editStrategy;
 
     private Optional<?> resolvedValue;
     private Object resolvedDefaultValue;
     private String jmxName;
 
-    public AttributeConfigElement(Object dafaultValue, Object value) {
-        this.dafaultValue = dafaultValue;
+    public AttributeConfigElement(Object defaultValue, Object value, final EditStrategyType editStrategyType) {
+        this.defaultValue = defaultValue;
         this.value = value;
+        this.editStrategy = Optional.fromNullable(editStrategyType);
     }
 
     public void setJmxName(String jmxName) {
@@ -42,22 +44,34 @@ public class AttributeConfigElement {
     public void resolveValue(AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy,
             String attrName) throws NetconfDocumentedException {
         resolvedValue = attributeResolvingStrategy.parseAttribute(attrName, value);
-        Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, dafaultValue);
+        Optional<?> resolvedDefault = attributeResolvingStrategy.parseAttribute(attrName, defaultValue);
         resolvedDefaultValue = resolvedDefault.isPresent() ? resolvedDefault.get() : null;
     }
 
+    public Optional<EditStrategyType> getEditStrategy() {
+        return editStrategy;
+    }
+
     public static AttributeConfigElement create(Object nullableDefault, Object value) {
-        return new AttributeConfigElement(nullableDefault, value);
+        return new AttributeConfigElement(nullableDefault, value, null);
     }
 
     public static AttributeConfigElement createNullValue(Object nullableDefault) {
-        return new AttributeConfigElement(nullableDefault, null);
+        return new AttributeConfigElement(nullableDefault, null, null);
+    }
+
+    public static AttributeConfigElement create(final String nullableDefault, final Object value, final EditStrategyType editStrategyType) {
+        return new AttributeConfigElement(nullableDefault, value, editStrategyType);
     }
 
     public Object getValue() {
         return value;
     }
 
+    public Object getDefaultValue() {
+        return defaultValue;
+    }
+
     public Optional<?> getResolvedValue() {
         return resolvedValue;
     }
@@ -68,7 +82,7 @@ public class AttributeConfigElement {
 
     @Override
     public String toString() {
-        return "AttributeConfigElement [dafaultValue=" + dafaultValue + ", value=" + value + "]";
+        return "AttributeConfigElement [defaultValue=" + defaultValue + ", value=" + value + "]";
     }
 
 }