2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.List;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingAugmentationCodecTreeNode;
14 import org.opendaylight.mdsal.binding.runtime.api.AugmentRuntimeType;
15 import org.opendaylight.yangtools.yang.binding.Augmentation;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 final class AugmentationCodecContext<D extends DataObject & Augmentation<?>>
24 extends AbstractDataObjectCodecContext<D, AugmentRuntimeType> implements BindingAugmentationCodecTreeNode<D> {
25 AugmentationCodecContext(final AugmentationCodecPrototype prototype) {
26 super(prototype, new CodecDataObjectAnalysis<>(prototype, CodecItemFactory.of(), null));
30 public PathArgument serializePathArgument(final InstanceIdentifier.PathArgument arg) {
31 if (!bindingArg().equals(arg)) {
32 throw new IllegalArgumentException("Unexpected argument " + arg);
38 public InstanceIdentifier.PathArgument deserializePathArgument(final PathArgument arg) {
40 throw new IllegalArgumentException("Unexpected argument " + arg);
46 public D filterFrom(final DataContainerNode parentData) {
47 for (var childArg : ((AugmentationCodecPrototype) prototype).getChildArgs()) {
48 if (parentData.childByArg(childArg) != null) {
49 return createBindingProxy(parentData);
56 public ImmutableSet<NodeIdentifier> childPathArguments() {
57 return byYangKeySet();
61 protected Object deserializeObject(final NormalizedNode normalizedNode) {
62 return filterFrom(checkDataArgument(DataContainerNode.class, normalizedNode));
66 void addYangPathArgument(final List<PathArgument> builder, final InstanceIdentifier.PathArgument arg) {
71 protected NodeIdentifier getDomPathArgument() {
76 Map<Class<? extends Augmentation<?>>, Augmentation<?>> getAllAugmentationsFrom(final DataContainerNode data) {