/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.binding.data.codec.impl;

import com.google.common.base.Optional;
import java.util.List;
import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;

abstract class DataContainerCodecContext<T> extends NodeCodecContext {

    private final DataContainerCodecPrototype<T> prototype;

    protected DataContainerCodecContext(final DataContainerCodecPrototype<T> prototype) {
        this.prototype = prototype;
    }

    protected final T schema() {
        return prototype.getSchema();
    }

    protected final QNameModule namespace() {
        return prototype.getNamespace();
    }

    protected final CodecContextFactory factory() {
        return prototype.getFactory();
    }

    @Override
    protected YangInstanceIdentifier.PathArgument getDomPathArgument() {
        return prototype.getYangArg();
    }

    /**
     * Returns nested node context using supplied YANG Instance Identifier
     *
     * @param arg Yang Instance Identifier Argument
     * @return Context of child
     * @throws IllegalArgumentException If supplied argument does not represent valid child.
     */
    protected abstract NodeCodecContext getYangIdentifierChild(final YangInstanceIdentifier.PathArgument arg);

    /**
     * Returns nested node context using supplied Binding Instance Identifier
     * and adds YANG instance identifiers to supplied list.
     *
     * @param arg Binding Instance Identifier Argument
     * @return Context of child
     * @throws IllegalArgumentException If supplied argument does not represent valid child.
     */
    protected  DataContainerCodecContext<?> getIdentifierChild(final InstanceIdentifier.PathArgument arg,
            final List<YangInstanceIdentifier.PathArgument> builder) {
        final DataContainerCodecContext<?> child = getStreamChild(arg.getType());
        if (builder != null) {
            child.addYangPathArgument(arg,builder);
        }
        return child;
    }

    /**
     * Returns deserialized Binding Path Argument from YANG instance identifier.
     *
     * @param domArg
     * @return
     */
    protected PathArgument getBindingPathArgument(final YangInstanceIdentifier.PathArgument domArg) {
        return bindingArg();
    }

    protected final PathArgument bindingArg() {
        return prototype.getBindingArg();
    }

    protected final Class<?> bindingClass() {
        return prototype.getBindingClass();
    }

    /**
     *
     * Returns child context as if it was walked by
     * {@link BindingStreamEventWriter}. This means that to enter case, one
     * must issue getChild(ChoiceClass).getChild(CaseClass).
     *
     * @param childClass
     * @return Context of child
     * @throws IllegalArgumentException If supplied child class is not valid in specified context.
     */
    protected abstract DataContainerCodecContext<?> getStreamChild(final Class<?> childClass) throws IllegalArgumentException;

    /**
    *
    * Returns child context as if it was walked by
    * {@link BindingStreamEventWriter}. This means that to enter case, one
    * must issue getChild(ChoiceClass).getChild(CaseClass).
    *
    * @param childClass
    * @return Context of child or Optional absent is supplied class is not applicable in context.
    */
   protected abstract Optional<DataContainerCodecContext<?>> getPossibleStreamChild(final Class<?> childClass);

    @Override
    public String toString() {
        return getClass().getSimpleName() + " [" + prototype.getBindingClass() + "]";
    }

}
@@ -3538,26 +3538,28 @@
     /**%0A    
+ 
 *%0A
+ 
     * Return
@@ -3593,24 +3593,25 @@
 s walked by%0A
+ 
     * %7B@link
@@ -3673,24 +3673,25 @@
 se, one%0A    
+ 
 * must issue
@@ -3730,24 +3730,25 @@
 CaseClass).%0A
+ 
     *%0A    * 
@@ -3741,24 +3741,25 @@
 %0A     *%0A    
+ 
 * @param chi
@@ -3762,24 +3762,25 @@
  childClass%0A
+ 
     * @retur
@@ -3869,19 +3869,21 @@
 xt.%0A    
+ 
 */%0A
+ 
    prote

Fix code alignment