X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContextIntrospector.java;h=0ee005a708c8d4c660ee3df2980b08045bb964d6;hb=fb830fa236f32513f759893270552e320c122c5d;hp=c94f86989f4c080b700d21f4a6a630085cff0665;hpb=ddb1bd8badd0b3f7c76f969d2c6a6d0064216939;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java index c94f86989f..0ee005a708 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospector.java @@ -20,8 +20,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import javax.management.ConstructorParameters; @@ -337,8 +339,12 @@ public class DatastoreContextIntrospector { // Call the setter method on the Builder instance. final Method setter = BUILDER_SETTERS.get(key); - setter.invoke(builder, constructorValueRecursively( - Primitives.wrap(setter.getParameterTypes()[0]), value.toString())); + if (value.getClass().isEnum()) { + setter.invoke(builder, value); + } else { + setter.invoke(builder, constructorValueRecursively( + Primitives.wrap(setter.getParameterTypes()[0]), value.toString())); + } return true; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException @@ -373,6 +379,18 @@ public class DatastoreContextIntrospector { LOG.debug("Type for property {}: {}, converting value {} ({})", name, propertyType.getSimpleName(), from, from.getClass().getSimpleName()); + if (propertyType.isEnum()) { + try { + final Method enumConstructor = propertyType.getDeclaredMethod("forName", String.class); + final Object optional = enumConstructor.invoke(null, from.toString().toLowerCase(Locale.ROOT)); + if (optional instanceof Optional) { + return ((Optional)optional).orElseThrow(); + } + } catch (NoSuchMethodException e) { + LOG.error("Error constructing value ({}) for enum {}", from, propertyType); + } + } + // Recurse the chain of constructors depth-first to get the resulting value. Eg, if the // property type is the yang-generated NonZeroUint32Type, it's constructor takes a Long so // we have to first construct a Long instance from the input value.