Ignore empty augmentations at runtime
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / CaseNodeCodecContext.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkState;
12
13 import java.util.List;
14 import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23
24 final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecContext<D, CaseRuntimeType> {
25     CaseNodeCodecContext(final DataContainerCodecPrototype<CaseRuntimeType> prototype) {
26         super(prototype);
27     }
28
29     @Override
30     @SuppressWarnings({ "unchecked", "rawtypes" })
31     Item<?> createBindingArg(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
32         // FIXME: MDSAL-697: see overridden method for further guidance
33         return childSchema instanceof AddedByUsesAware && ((AddedByUsesAware) childSchema).isAddedByUses()
34             ? Item.of((Class)getBindingClass(), (Class)childClass)
35                 : super.createBindingArg(childClass, childSchema);
36     }
37
38     @Override
39     protected void addYangPathArgument(final PathArgument arg,
40             final List<YangInstanceIdentifier.PathArgument> builder) {
41         // NOOP
42     }
43
44     @Override
45     public D deserialize(final NormalizedNode data) {
46         checkState(data instanceof ChoiceNode, "Unexpected data %s", data);
47         return createBindingProxy((ChoiceNode) data);
48     }
49
50     @Override
51     protected Object deserializeObject(final NormalizedNode normalizedNode) {
52         return deserialize(normalizedNode);
53     }
54
55     @Override
56     public YangInstanceIdentifier.PathArgument serializePathArgument(final PathArgument arg) {
57         checkArgument(arg == null, "Unexpected argument %s", arg);
58         return null;
59     }
60
61     @Override
62     public PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
63         checkArgument(arg == null, "Unexpected argument %s", arg);
64         return null;
65     }
66 }