import org.opendaylight.yangtools.sal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.binding.Augmentable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.AugmentationHolder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
byBindingArgClassBuilder.putAll(byStreamClass);
this.byBindingArgClass = ImmutableMap.copyOf(byBindingArgClassBuilder);
- final Class<?> proxyClass = Proxy.getProxyClass(getBindingClass().getClassLoader(), new Class[] { getBindingClass() });
+ final Class<?> proxyClass = Proxy.getProxyClass(getBindingClass().getClassLoader(), new Class[] { getBindingClass(), AugmentationHolder.class });
try {
proxyConstructor = LOOKUP.findConstructor(proxyClass, CONSTRUCTOR_TYPE).asType(DATAOBJECT_TYPE);
} catch (NoSuchMethodException | IllegalAccessException e) {
}
}
}
- Preconditions.checkArgument(childProto != null, " Child %s is not valid child.",childClass);
- return (DataContainerCodecContext<DV, ?>) childProto.get();
+ return (DataContainerCodecContext<DV, ?>) childNonNull(childProto, childClass, " Child %s is not valid child.").get();
}
@SuppressWarnings("unchecked")
@Override
public <DV extends DataObject> Optional<DataContainerCodecContext<DV, ?>> possibleStreamChild(
- Class<DV> childClass) {
+ final Class<DV> childClass) {
final DataContainerCodecPrototype<?> childProto = byStreamClass.get(childClass);
if(childProto != null) {
return Optional.<DataContainerCodecContext<DV,?>>of((DataContainerCodecContext<DV,?>) childProto.get());
final Class<? extends DataObject> argType = arg.getType();
final DataContainerCodecPrototype<?> ctxProto = byBindingArgClass.get(argType);
- if(ctxProto != null) {
- final DataContainerCodecContext<?,?> context = ctxProto.get();
- if(context instanceof ChoiceNodeCodecContext) {
- final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) context;
- final DataContainerCodecContext<?,?> caze = choice.getCazeByChildClass(arg.getType());
- if(caze != null) {
- choice.addYangPathArgument(arg, builder);
- caze.addYangPathArgument(arg, builder);
- return caze.bindingPathArgumentChild(arg, builder);
- }
- return null;
- }
- context.addYangPathArgument(arg, builder);
- return context;
+ final DataContainerCodecContext<?, ?> context =
+ childNonNull(ctxProto, argType, "Class %s is not valid child of %s", argType, getBindingClass()).get();
+ if (context instanceof ChoiceNodeCodecContext) {
+ final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) context;
+ final DataContainerCodecContext<?, ?> caze = choice.getCazeByChildClass(arg.getType());
+ choice.addYangPathArgument(arg, builder);
+ caze.addYangPathArgument(arg, builder);
+ return caze.bindingPathArgumentChild(arg, builder);
}
- // Argument is not valid child.
- return null;
+ context.addYangPathArgument(arg, builder);
+ return context;
}
@SuppressWarnings("unchecked")
arg = new NodeIdentifier(arg.getNodeType());
}
final NodeContextSupplier childSupplier = byYang.get(arg);
- Preconditions.checkArgument(childSupplier != null, "Argument %s is not valid child of %s", arg, schema());
+ childNonNull(childSupplier != null, arg, "Argument %s is not valid child of %s", arg, schema());
return (NodeCodecContext<D>) childSupplier.get();
}
protected final LeafNodeCodecContext<?> getLeafChild(final String name) {
final LeafNodeCodecContext<?> value = leafChild.get(name);
- Preconditions.checkArgument(value != null, "Leaf %s is not valid for %s", name, getBindingClass());
- return value;
+ return IncorrectNestingException.checkNonNull(value, "Leaf %s is not valid for %s", name, getBindingClass());
}
private DataContainerCodecPrototype<?> loadChildPrototype(final Class<?> childClass) {
childSchema = null;
}
}
- Preconditions.checkArgument(childSchema != null, "Node %s does not have child named %s", schema(), childClass);
- return DataContainerCodecPrototype.from(childClass, childSchema, factory());
+ final DataSchemaNode nonNullChild =
+ childNonNull(childSchema, childClass, "Node %s does not have child named %s", schema(), childClass);
+ return DataContainerCodecPrototype.from(childClass, nonNullChild, factory());
}
private DataContainerCodecPrototype<?> getAugmentationPrototype(final Type value) {
return byMethod.keySet();
}
+ @Override
+ public InstanceIdentifier.PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
+ Preconditions.checkArgument(getDomPathArgument().equals(arg));
+ return bindingArg();
+ }
+
+ @Override
+ public YangInstanceIdentifier.PathArgument serializePathArgument(final InstanceIdentifier.PathArgument arg) {
+ Preconditions.checkArgument(bindingArg().equals(arg));
+ return getDomPathArgument();
+ }
}