*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
-import java.lang.reflect.Method;
+import static org.opendaylight.mdsal.binding.spec.naming.BindingMapping.IDENTIFIABLE_KEY_NAME;
+
import java.util.List;
-import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
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;
+ private final IdentifiableItemCodec codec;
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(IDENTIFIABLE_KEY_NAME);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Required method not available", e);
}
}
@Override
- protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) {
+ protected void addYangPathArgument(final InstanceIdentifier.PathArgument arg,
+ final List<YangInstanceIdentifier.PathArgument> builder) {
/*
- * DOM Instance Identifier for list is always represent by two
- * entries one for map and one for children. This is also true for
- * wildcarded instance identifiers
+ * DOM Instance Identifier for list is always represent by two entries one for map and one for children. This
+ * is also true for wildcarded instance identifiers
*/
if (builder == null) {
return;
}
super.addYangPathArgument(arg, builder);
- if (arg instanceof IdentifiableItem<?, ?>) {
+ if (arg instanceof IdentifiableItem) {
builder.add(codec.serialize((IdentifiableItem<?, ?>) arg));
} else {
// Adding wildcarded
@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 && IDENTIFIABLE_KEY_NAME.equals(methodName)) {
NodeIdentifierWithPredicates identifier = ((MapEntryNode) dom).getIdentifier();
return codec.deserialize(identifier).getKey();
- } else {
- return super.getBindingChildValue(method, dom);
}
+ return super.getBindingChildValue(methodName, dom);
}
@Override
- protected InstanceIdentifier.PathArgument getBindingPathArgument(final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument domArg) {
+ protected InstanceIdentifier.PathArgument getBindingPathArgument(final YangInstanceIdentifier.PathArgument domArg) {
if (domArg instanceof NodeIdentifierWithPredicates) {
return codec.deserialize((NodeIdentifierWithPredicates) domArg);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
NodeIdentifierWithPredicates serialize(final Identifier<?> key) {
- return codec.serialize(new IdentifiableItem(getBindingClass(), key));
+ return codec.serialize(IdentifiableItem.of((Class)getBindingClass(), (Identifier)key));
}
@Override
public YangInstanceIdentifier.PathArgument serializePathArgument(final InstanceIdentifier.PathArgument arg) {
- if(arg instanceof IdentifiableItem) {
- return codec.serialize((IdentifiableItem<?,?>) arg);
+ if (arg instanceof IdentifiableItem) {
+ return codec.serialize((IdentifiableItem<?, ?>) arg);
}
return super.serializePathArgument(arg);
}
@Override
public InstanceIdentifier.PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
- if(arg instanceof NodeIdentifierWithPredicates) {
+ if (arg instanceof NodeIdentifierWithPredicates) {
return codec.deserialize((NodeIdentifierWithPredicates) arg);
}
return super.deserializePathArgument(arg);
}
-
-
}