Index getter methods by String
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / KeyedListNodeCodecContext.java
index da8438980dd1c0d098a905fe0e73c896a6d2737e..ceb30a41b1b2d65625ea0fab6fdaaec8addd0c9b 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
-import java.lang.reflect.Method;
 import java.util.List;
 import org.opendaylight.yangtools.concepts.Codec;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -23,14 +22,15 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
 final class KeyedListNodeCodecContext<D extends DataObject & Identifiable<?>> extends ListNodeCodecContext<D> {
     private final Codec<NodeIdentifierWithPredicates, IdentifiableItem<?, ?>> codec;
-    private final Method keyGetter;
 
     KeyedListNodeCodecContext(final DataContainerCodecPrototype<ListSchemaNode> prototype) {
         super(prototype);
 
-        this.codec = factory().getPathArgumentCodec(getBindingClass(), getSchema());
+        final Class<D> bindingClass = getBindingClass();
+        this.codec = factory().getPathArgumentCodec(bindingClass, getSchema());
         try {
-            this.keyGetter = getBindingClass().getMethod("getKey");
+            // This just verifies the method is present
+            bindingClass.getMethod("getKey");
         } catch (NoSuchMethodException e) {
             throw new IllegalStateException("Required method not available", e);
         }
@@ -58,12 +58,12 @@ final class KeyedListNodeCodecContext<D extends DataObject & Identifiable<?>> ex
 
     @Override
     @SuppressWarnings("rawtypes")
-    Object getBindingChildValue(final Method method, final NormalizedNodeContainer dom) {
-        if (dom instanceof MapEntryNode && keyGetter.equals(method)) {
+    Object getBindingChildValue(final String methodName, final NormalizedNodeContainer dom) {
+        if (dom instanceof MapEntryNode && "getKey".equals(methodName)) {
             NodeIdentifierWithPredicates identifier = ((MapEntryNode) dom).getIdentifier();
             return codec.deserialize(identifier).getKey();
         }
-        return super.getBindingChildValue(method, dom);
+        return super.getBindingChildValue(methodName, dom);
     }
 
     @Override