* @param binding
* Binding Instance Identifier
* @return DOM Instance Identifier
+ * @throws IllegalArgumentException
+ * If supplied Instance Identifier is not valid.
*/
YangInstanceIdentifier toYangInstanceIdentifier(@Nonnull InstanceIdentifier<?> binding);
* @param data
* Data object representing data
* @return NormalizedNode representation
+ * @throws IllegalArgumentException
+ * If supplied Instance Identifier is not valid.
*/
<T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
InstanceIdentifier<T> path, T data);
* Stream writer on which events will be invoked.
* @return Instance Identifier and {@link BindingStreamEventWriter}
* which will write to supplied {@link NormalizedNodeStreamWriter}.
+ * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
*/
@Nonnull Entry<YangInstanceIdentifier, BindingStreamEventWriter> newWriterAndIdentifier(@Nonnull InstanceIdentifier<?> path,
@Nonnull NormalizedNodeStreamWriter domWriter);
* @param domWriter Stream writer on which events will be invoked.
* @return {@link BindingStreamEventWriter}
* which will write to supplied {@link NormalizedNodeStreamWriter}.
+ * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
*/
@Nonnull
BindingStreamEventWriter newWriter(@Nonnull InstanceIdentifier<?> path,
DataContainerCodecContext<?> currentNode = root;
for (final InstanceIdentifier.PathArgument bindingArg : binding.getPathArguments()) {
currentNode = currentNode.getIdentifierChild(bindingArg, builder);
+ Preconditions.checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.",binding);
}
return currentNode;
}
* @param bindingArguments Collection for traversed path arguments
* @return Codec for target node, or @null if the node does not have a
* binding representation (choice, case, leaf).
+ *
*/
@Nullable NodeCodecContext getCodecContextNode(final @Nonnull YangInstanceIdentifier dom,
final @Nonnull Collection<InstanceIdentifier.PathArgument> bindingArguments) {
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
-
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
return caze.get().dataFromNormalizedNode(data);
}
- public DataContainerCodecContext<?> getCazeByChildClass(final Class<? extends DataObject> type) {
- return byCaseChildClass.get(type).get();
+ public @Nullable DataContainerCodecContext<?> getCazeByChildClass(final @Nonnull Class<? extends DataObject> type) {
+ final DataContainerCodecPrototype<?> protoCtx = byCaseChildClass.get(type);
+ if(protoCtx != null) {
+ return protoCtx.get();
+ }
+ return null;
}
}
import com.google.common.base.Optional;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
* and adds YANG instance identifiers to supplied list.
*
* @param arg Binding Instance Identifier Argument
- * @return Context of child
+ * @return Context of child or null if supplied {@code arg} does not represent valid child.
* @throws IllegalArgumentException If supplied argument does not represent valid child.
*/
- protected DataContainerCodecContext<?> getIdentifierChild(final InstanceIdentifier.PathArgument arg,
+ protected @Nullable DataContainerCodecContext<?> getIdentifierChild(final InstanceIdentifier.PathArgument arg,
final List<YangInstanceIdentifier.PathArgument> builder) {
final DataContainerCodecContext<?> child = getStreamChild(arg.getType());
- if (builder != null) {
- child.addYangPathArgument(arg,builder);
+ if(child != null) {
+ if (builder != null) {
+ child.addYangPathArgument(arg,builder);
+ }
+ return child;
}
- return child;
+ return null;
}
/**
* must issue getChild(ChoiceClass).getChild(CaseClass).
*
* @param childClass
- * @return Context of child
+ * @return Context of child node or null, if supplied class is not subtree child
* @throws IllegalArgumentException If supplied child class is not valid in specified context.
*/
- protected abstract DataContainerCodecContext<?> getStreamChild(final Class<?> childClass) throws IllegalArgumentException;
+ protected abstract @Nullable DataContainerCodecContext<?> getStreamChild(final Class<?> childClass) throws IllegalArgumentException;
/**
*
protected DataContainerCodecContext<?> getIdentifierChild(final InstanceIdentifier.PathArgument arg,
final List<YangInstanceIdentifier.PathArgument> builder) {
- Class<? extends DataObject> argType = arg.getType();
- DataContainerCodecPrototype<?> ctxProto = byBindingArgClass.get(argType);
- Preconditions.checkArgument(ctxProto != null,"Invalid child");
-
- DataContainerCodecContext<?> context = ctxProto.get();
- if(context instanceof ChoiceNodeCodecContext) {
- ChoiceNodeCodecContext casted = (ChoiceNodeCodecContext) context;
- casted.addYangPathArgument(arg, builder);
- DataContainerCodecContext<?> caze = casted.getCazeByChildClass(arg.getType());
- caze.addYangPathArgument(arg, builder);
- return caze.getIdentifierChild(arg, builder);
+ 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.getIdentifierChild(arg, builder);
+ }
+ return null;
+ }
+ context.addYangPathArgument(arg, builder);
+ return context;
}
- context.addYangPathArgument(arg, builder);
- return context;
+ // Argument is not valid child.
+ return null;
}
@Override