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.yangtools.binding.data.codec.impl;
10 import java.util.List;
12 import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 abstract class DataContainerCodecContext<T> extends NodeCodecContext {
20 private final DataContainerCodecPrototype<T> prototype;
22 protected DataContainerCodecContext(final DataContainerCodecPrototype<T> prototype) {
23 this.prototype = prototype;
26 protected final T schema() {
27 return prototype.getSchema();
30 protected final QNameModule namespace() {
31 return prototype.getNamespace();
34 protected final CodecContextFactory factory() {
35 return prototype.getFactory();
39 protected YangInstanceIdentifier.PathArgument getDomPathArgument() {
40 return prototype.getYangArg();
44 * Returns nested node context using supplied YANG Instance Identifier
46 * @param arg Yang Instance Identifier Argument
47 * @return Context of child
48 * @throws IllegalArgumentException If supplied argument does not represent valid child.
50 protected abstract NodeCodecContext getYangIdentifierChild(final YangInstanceIdentifier.PathArgument arg);
53 * Returns nested node context using supplied Binding Instance Identifier
54 * and adds YANG instance identifiers to supplied list.
56 * @param arg Binding Instance Identifier Argument
57 * @return Context of child
58 * @throws IllegalArgumentException If supplied argument does not represent valid child.
60 protected DataContainerCodecContext<?> getIdentifierChild(final InstanceIdentifier.PathArgument arg,
61 final List<YangInstanceIdentifier.PathArgument> builder) {
62 final DataContainerCodecContext<?> child = getStreamChild(arg.getType());
63 if (builder != null) {
64 child.addYangPathArgument(arg,builder);
70 * Returns deserialized Binding Path Argument from YANG instance identifier.
75 protected PathArgument getBindingPathArgument(final YangInstanceIdentifier.PathArgument domArg) {
79 protected final PathArgument bindingArg() {
80 return prototype.getBindingArg();
83 protected final Class<?> bindingClass() {
84 return prototype.getBindingClass();
89 * Returns child context as if it was walked by
90 * {@link BindingStreamEventWriter}. This means that to enter case, one
91 * must issue getChild(ChoiceClass).getChild(CaseClass).
94 * @return Context of child
96 protected abstract DataContainerCodecContext<?> getStreamChild(final Class<?> childClass);
99 public String toString() {
100 return getClass().getSimpleName() + " [" + prototype.getBindingClass() + "]";