69c94c6a93f07c14bf7356a07da27cb973a6e146
[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
12 import java.util.List;
13 import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecContext<D, CaseRuntimeType> {
22     static final class Prototype extends DataObjectCodecPrototype<CaseRuntimeType> {
23         Prototype(final Class<?> cls, final CaseRuntimeType type, final CodecContextFactory factory) {
24             super(cls, NodeIdentifier.create(type.statement().argument()), type, factory);
25         }
26
27         @Override
28         DataContainerCodecContext<?, CaseRuntimeType> createInstance() {
29             return new CaseNodeCodecContext<>(this);
30         }
31     }
32
33     private CaseNodeCodecContext(final Prototype prototype) {
34         super(prototype, CodecItemFactory.of(prototype.getBindingClass()));
35     }
36
37     @Override
38     void addYangPathArgument(final PathArgument arg, final List<YangInstanceIdentifier.PathArgument> builder) {
39         // NOOP
40     }
41
42     @Override
43     public D deserialize(final NormalizedNode data) {
44         return createBindingProxy(checkDataArgument(ChoiceNode.class, data));
45     }
46
47     @Override
48     protected Object deserializeObject(final NormalizedNode normalizedNode) {
49         return deserialize(normalizedNode);
50     }
51
52     @Override
53     public YangInstanceIdentifier.PathArgument serializePathArgument(final PathArgument arg) {
54         checkArgument(arg == null, "Unexpected argument %s", arg);
55         return null;
56     }
57
58     @Override
59     public PathArgument deserializePathArgument(final YangInstanceIdentifier.PathArgument arg) {
60         checkArgument(arg == null, "Unexpected argument %s", arg);
61         return null;
62     }
63 }