[ONOS-5088] YANG SBI Broker Implementation.

Change-Id: Ibe87e095a4c209c54e3e90aceca0ec9097c5ede0
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java
new file mode 100644
index 0000000..8ba016d
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/DefaultYangCodecHandler.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych;
+
+import org.onosproject.yms.app.ych.defaultcodecs.YangCodecRegistry;
+import org.onosproject.yms.app.ydt.YdtExtendedBuilder;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.yob.DefaultYobBuilder;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.app.ytb.DefaultYangTreeBuilder;
+import org.onosproject.yms.app.ytb.YtbException;
+import org.onosproject.yms.ych.YangCodecHandler;
+import org.onosproject.yms.ych.YangCompositeEncoding;
+import org.onosproject.yms.ych.YangDataTreeCodec;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.onosproject.yms.app.ych.defaultcodecs.utils.DefaultCodecUtils.isNonEmpty;
+
+
+/**
+ * Represents implementation of YANG SBI broker interfaces.
+ * YCH acts as a broker between YMS and driver/provider.
+ */
+public class DefaultYangCodecHandler implements YangCodecHandler {
+
+    private static final String E_MODULE_LIST = "The input module or " +
+            "sub-module object list cannot be null.";
+    private static final String E_DATA_TREE_CODEC = "data tree codec handler" +
+            " is null.";
+
+    /**
+     * Schema registry for driver.
+     */
+    private final YangSchemaRegistry schemaRegistry;
+
+    /**
+     * Default codecs.
+     */
+    private final Map<YangProtocolEncodingFormat, YangDataTreeCodec>
+            defaultCodecs = new HashMap<>();
+
+    /**
+     * Override codec handler.
+     */
+    private final Map<YangProtocolEncodingFormat, YangDataTreeCodec>
+            overrideCodecs = new HashMap<>();
+
+    /**
+     * Creates a new YANG codec handler.
+     *
+     * @param registry YANG schema registry
+     */
+    public DefaultYangCodecHandler(YangSchemaRegistry registry) {
+        schemaRegistry = registry;
+
+        // update the default codecs from codec registry
+        Map<YangProtocolEncodingFormat, YangDataTreeCodec> recvCodec =
+                YangCodecRegistry.getDefaultCodecs();
+        if (!recvCodec.isEmpty()) {
+            for (Map.Entry<YangProtocolEncodingFormat, YangDataTreeCodec>
+                    codecEntry : recvCodec.entrySet()) {
+                defaultCodecs.put(codecEntry.getKey(), codecEntry.getValue());
+            }
+        }
+    }
+
+    private YangDataTreeCodec getAppropriateCodec(
+            YangProtocolEncodingFormat dataFormat) {
+        YangDataTreeCodec codec = defaultCodecs.get(dataFormat);
+
+        // Check over ridden codec handler is exist or not.
+        if (overrideCodecs != null) {
+            YangDataTreeCodec overrideCodec = overrideCodecs.get(dataFormat);
+            if (overrideCodec != null) {
+                codec = overrideCodec;
+            }
+        }
+        return codec;
+    }
+
+    @Override
+    public void addDeviceSchema(Class<?> yangModule) {
+        schemaRegistry.registerApplication(null, yangModule, null);
+    }
+
+    @Override
+    public String encodeOperation(String rootName,
+                                  String rootNamespace,
+                                  Map<String, String> tagAttrMap,
+                                  List<Object> moduleList,
+                                  YangProtocolEncodingFormat dataFormat,
+                                  YmsOperationType opType) {
+
+        if (moduleList == null || moduleList.isEmpty()) {
+            throw new YchException(E_MODULE_LIST);
+        }
+
+        // Get the default codec handler.
+        YangDataTreeCodec codec = getAppropriateCodec(dataFormat);
+        if (codec == null) {
+            throw new YchException(E_DATA_TREE_CODEC);
+        }
+
+        // Get yang data tree from YTB for the received objects.
+        DefaultYangTreeBuilder builder = new DefaultYangTreeBuilder();
+        YdtExtendedBuilder encodedYdt =
+                builder.getYdtBuilderForYo(moduleList, rootName,
+                                           rootNamespace, opType,
+                                           schemaRegistry);
+
+        encodedYdt.setRootTagAttributeMap(tagAttrMap);
+
+        // Get the xml string form codec handler.
+        return codec.encodeYdtToProtocolFormat(encodedYdt);
+    }
+
+    @Override
+    public YangCompositeEncoding encodeCompositeOperation(
+            String rootName,
+            String rootNamespace,
+            Object moduleObject,
+            YangProtocolEncodingFormat dataFormat,
+            YmsOperationType opType) {
+
+        if (moduleObject == null) {
+            throw new YtbException(E_MODULE_LIST);
+        }
+
+        // Get the default codec handler.
+        YangDataTreeCodec codec = getAppropriateCodec(dataFormat);
+        if (codec == null) {
+            throw new YchException(E_DATA_TREE_CODEC);
+        }
+
+        List<Object> yangModuleList = new ArrayList<>();
+        yangModuleList.add(moduleObject);
+
+        // Get yang data tree from YTB for the received objects.
+        DefaultYangTreeBuilder builder = new DefaultYangTreeBuilder();
+        YdtExtendedBuilder extBuilder =
+                builder.getYdtBuilderForYo(yangModuleList,
+                                           rootName,
+                                           rootNamespace,
+                                           opType,
+                                           schemaRegistry);
+
+
+        // Get the composite response from codec handler.
+        return codec.encodeYdtToCompositeProtocolFormat(extBuilder);
+    }
+
+    @Override
+    public List<Object> decode(String inputString,
+                               YangProtocolEncodingFormat dataFormat,
+                               YmsOperationType opType) {
+
+        YangDataTreeCodec codec = getAppropriateCodec(dataFormat);
+        if (codec == null) {
+            throw new YchException(E_DATA_TREE_CODEC);
+        }
+
+        // Get the YANG data tree
+        YdtBuilder ydtBuilder = codec.decodeProtocolDataToYdt(inputString,
+                                                              schemaRegistry,
+                                                              opType);
+
+        if (ydtBuilder != null) {
+            return getObjectList(ydtBuilder.getRootNode());
+        }
+
+        return null;
+    }
+
+    @Override
+    public Object decode(YangCompositeEncoding protoData,
+                         YangProtocolEncodingFormat dataFormat,
+                         YmsOperationType opType) {
+
+        YangDataTreeCodec codec = getAppropriateCodec(dataFormat);
+        if (codec == null) {
+            throw new YchException(E_DATA_TREE_CODEC);
+        }
+
+        YdtBuilder ydtBuilder =
+                codec.decodeCompositeProtocolDataToYdt(protoData,
+                                                       schemaRegistry,
+                                                       opType);
+
+        // Get the module object by using YANG data tree
+        if (ydtBuilder != null) {
+            List<Object> objectList = getObjectList(ydtBuilder.getRootNode());
+            if (isNonEmpty(objectList)) {
+                return objectList.get(0);
+            }
+        }
+
+        return null;
+    }
+
+    @Override
+    public void registerOverriddenCodec(YangDataTreeCodec overrideCodec,
+                                        YangProtocolEncodingFormat dataFormat) {
+        overrideCodecs.put(dataFormat, overrideCodec);
+    }
+
+    /**
+     * Returns the list of objects from YDT data tree.
+     *
+     * @param rootNode YDT root node
+     * @return returns list of objects
+     */
+    private List<Object> getObjectList(YdtContext rootNode) {
+
+        if (rootNode == null) {
+            // TODO
+            return null;
+        }
+
+        if (rootNode.getFirstChild() == null) {
+            // TODO
+            return null;
+        }
+
+        YdtContext curNode = rootNode.getFirstChild();
+        DefaultYobBuilder builder = new DefaultYobBuilder();
+        Object object = builder.getYangObject((YdtExtendedContext) curNode,
+                                              schemaRegistry);
+        List<Object> objectList = new ArrayList<>();
+        objectList.add(object);
+
+        // Check next module is exit or not. If exist get the object for that.
+        while (curNode.getNextSibling() != null) {
+            curNode = curNode.getNextSibling();
+            object = builder.getYangObject((YdtExtendedContext) curNode,
+                                           schemaRegistry);
+            objectList.add(object);
+        }
+
+        return objectList;
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/YchException.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/YchException.java
new file mode 100644
index 0000000..bc6cbaa
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/YchException.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych;
+
+/**
+ * Represents base class for exceptions in YCH operations.
+ */
+public class YchException extends RuntimeException {
+    private static final long serialVersionUID = 20160211L;
+
+    /**
+     * Creates a new YCH exception.
+     */
+    public YchException() {
+    }
+
+    /**
+     * Creates a new YCH exception with given message.
+     *
+     * @param message the detail of exception in string
+     */
+    public YchException(String message) {
+        super(message);
+    }
+
+    /**
+     * Creates a new YCH exception from given message and cause.
+     *
+     * @param message the detail of exception in string
+     * @param cause   underlying cause of the error
+     */
+    public YchException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Creates a new YCH exception from cause.
+     *
+     * @param cause underlying cause of the error
+     */
+    public YchException(Throwable cause) {
+        super(cause);
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/CodecHandlerFactory.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/CodecHandlerFactory.java
new file mode 100644
index 0000000..b734239
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/CodecHandlerFactory.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs;
+
+
+import org.onosproject.yms.app.ych.YchException;
+import org.onosproject.yms.app.ych.defaultcodecs.xml.XmlCodecHandler;
+import org.onosproject.yms.app.ych.defaultcodecs.xml.XmlCodecMultiInstanceHandler;
+import org.onosproject.yms.app.ych.defaultcodecs.xml.XmlCodecMultiInstanceLeafHandler;
+import org.onosproject.yms.app.ych.defaultcodecs.xml.XmlCodecSingleInstanceHandler;
+import org.onosproject.yms.app.ych.defaultcodecs.xml.XmlCodecSingleInstanceLeafHandler;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
+
+/**
+ * Represents an YCH handle factory to create different types of YANG data tree
+ * node.
+ */
+public final class CodecHandlerFactory {
+
+    private static final Logger log =
+            LoggerFactory.getLogger(CodecHandlerFactory.class);
+    private static final String YDT_TYPE_ERROR = "YDT type is not supported.";
+
+    /**
+     * Map of xml codec handler.
+     */
+    private final Map<YdtType, XmlCodecHandler> handlerMap;
+
+    /**
+     * Creates a new codec handler factory.
+     */
+    private CodecHandlerFactory() {
+        handlerMap = new HashMap<>();
+        handlerMap.put(SINGLE_INSTANCE_NODE,
+                       new XmlCodecSingleInstanceHandler());
+        handlerMap.put(MULTI_INSTANCE_NODE,
+                       new XmlCodecMultiInstanceHandler());
+        handlerMap.put(SINGLE_INSTANCE_LEAF_VALUE_NODE,
+                       new XmlCodecSingleInstanceLeafHandler());
+        handlerMap.put(MULTI_INSTANCE_LEAF_VALUE_NODE,
+                       new XmlCodecMultiInstanceLeafHandler());
+    }
+
+    /**
+     * Returns YCH instance handler node instance.
+     *
+     * @param node   YDT context node
+     * @param format data format type expected from driver
+     * @return returns YCH handler node instance
+     */
+    public XmlCodecHandler getCodecHandlerForContext(
+            YdtContext node,
+            YangProtocolEncodingFormat format) {
+        if (format == XML) {
+            XmlCodecHandler handler = handlerMap.get(node.getYdtType());
+            if (handler == null) {
+                throw new YchException(YDT_TYPE_ERROR + node.getYdtType());
+            }
+            return handler;
+        }
+        log.error("{} data format is not supported.", format);
+        return null;
+    }
+
+    /*
+     * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the
+     * LazyHolder class is loaded via a call to the instance() method below.
+     */
+    private static class LazyHolder {
+        private static final CodecHandlerFactory INSTANCE =
+                new CodecHandlerFactory();
+    }
+
+    /**
+     * Returns a reference to the Singleton Codec Handler factory.
+     *
+     * @return the singleton codec handler factory
+     */
+    public static CodecHandlerFactory instance() {
+        return LazyHolder.INSTANCE;
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/YangCodecRegistry.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/YangCodecRegistry.java
new file mode 100644
index 0000000..2050b56
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/YangCodecRegistry.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs;
+
+import org.onosproject.yms.app.ych.defaultcodecs.xml.DefaultXmlCodec;
+import org.onosproject.yms.ych.YangDataTreeCodec;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML;
+
+/**
+ * Default implementation of YANG codec registry.
+ */
+public final class YangCodecRegistry {
+
+    // no instantiation
+    private YangCodecRegistry() {
+    }
+
+    /**
+     * Default codec map.
+     */
+    private static final Map<YangProtocolEncodingFormat, YangDataTreeCodec>
+            DEFAULT_CODECS = new HashMap<>();
+
+    /**
+     * Initialise the default codec map.
+     */
+    public static void initializeDefaultCodec() {
+        DEFAULT_CODECS.put(XML, new DefaultXmlCodec());
+    }
+
+    /**
+     * Returns the default codec map.
+     *
+     * @return the default codec map
+     */
+    public static Map<YangProtocolEncodingFormat, YangDataTreeCodec> getDefaultCodecs() {
+        return Collections.unmodifiableMap(DEFAULT_CODECS);
+    }
+
+    /**
+     * Registers a default codec for the specified data format.
+     *
+     * @param defaultCodec registered data tree codec
+     * @param dataFormat   protocol encoding data format
+     */
+    public static void registerDefaultCodec(
+            YangDataTreeCodec defaultCodec,
+            YangProtocolEncodingFormat dataFormat) {
+        DEFAULT_CODECS.put(dataFormat, defaultCodec);
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodec.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodec.java
new file mode 100644
index 0000000..8b50d33
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodec.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.netconf;
+
+import com.google.common.collect.ImmutableSet;
+import org.dom4j.Element;
+import org.onosproject.yms.app.ych.YchException;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.CONFIG;
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.DATA;
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.EDIT_CONFIG;
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.FILTER;
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.GET;
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.GET_CONFIG;
+import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.QUERY_REQUEST;
+
+/**
+ * Represents an YCH netconf codec to find the root element in the xml string.
+ */
+public class NetconfCodec {
+
+    private static final String PROTO_OPER_ERROR = "Received protocol " +
+            "operation is not same as in the XML string: ";
+    private static final Set<String> ALLOWABLE_NAMES =
+            ImmutableSet.of(CONFIG, DATA, FILTER);
+
+    /**
+     * Validate the operation type.
+     *
+     * @param elementName tag name in the xml string
+     * @param opType      operation type
+     */
+    private void validateOpType(String elementName, YmsOperationType opType) {
+        switch (elementName) {
+            // edit-config tag name is found in xml then check the
+            // interaction type.
+            case EDIT_CONFIG: {
+                if (opType != EDIT_CONFIG_REQUEST) {
+                    throw new YchException(PROTO_OPER_ERROR + opType);
+                }
+                break;
+            }
+
+            // get-config tag name is found in xml then check the
+            // interaction type.
+            case GET_CONFIG: {
+                if (opType != QUERY_CONFIG_REQUEST) {
+                    throw new YchException(PROTO_OPER_ERROR + opType);
+                }
+                break;
+            }
+
+            // get tag name is found in xml then check the interaction type.
+            case GET: {
+                if (opType != QUERY_REQUEST) {
+                    throw new YchException(PROTO_OPER_ERROR + opType);
+                }
+                break;
+            }
+
+            default: {
+                //TODO
+            }
+        }
+
+    }
+
+    /**
+     * Returns the data root element based on the NETCONF operation parameter.
+     *
+     * @param rootElement root element of document tree to find the root node
+     * @param opType      protocol operation being performed
+     * @return the data root node element
+     */
+    public Element getDataRootElement(Element rootElement,
+                                      YmsOperationType opType) {
+
+        Element retElement = null;
+        String elementName = rootElement.getName();
+        try {
+            validateOpType(elementName, opType);
+            // If config tag name is found then set the root element node.
+            if (ALLOWABLE_NAMES.contains(elementName)) {
+                return rootElement;
+            }
+
+            // If element has child node then traverse through the child node
+            // by recursively calling getDataRootElement method.
+            if (rootElement.hasContent() && !rootElement.isTextOnly()) {
+                for (Iterator i = rootElement.elementIterator();
+                     i.hasNext();) {
+                    Element childElement = (Element) i.next();
+                    retElement = getDataRootElement(childElement, opType);
+                }
+            }
+
+        } catch (Exception e) {
+            // TODO
+        }
+
+        return retElement;
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodecConstants.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodecConstants.java
new file mode 100644
index 0000000..bf0ee49
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/NetconfCodecConstants.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.netconf;
+
+/**
+ * Represents utilities constants which are used while codec encoding
+ * and decoding.
+ */
+public final class NetconfCodecConstants {
+
+    // no instantiation
+    private NetconfCodecConstants() {
+    }
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String EDIT_CONFIG = "edit-config";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String GET_CONFIG = "get-config";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String GET = "get";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String CONFIG = "config";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String DATA = "data";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    static final String FILTER = "filter";
+
+    /**
+     * Static attribute for edit config string.
+     */
+    public static final String OPERATION = "operation";
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/package-info.java
new file mode 100644
index 0000000..e37cb16
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/netconf/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provides implementation of default codec handler for netconf related
+ * operation.
+ */
+package org.onosproject.yms.app.ych.defaultcodecs.netconf;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/package-info.java
new file mode 100644
index 0000000..2b3da2b
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Default codec to support protocol data format encoding and decoding of the YANG objects.
+ */
+package org.onosproject.yms.app.ych.defaultcodecs;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/DefaultCodecUtils.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/DefaultCodecUtils.java
new file mode 100644
index 0000000..1d9e339
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/DefaultCodecUtils.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.utils;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import org.onosproject.yms.app.ych.YchException;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
+
+/**
+ * Utils to complete the conversion between JSON and YDT(YANG DATA MODEL).
+ */
+public final class DefaultCodecUtils {
+
+    private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+    private static final Splitter COMMA_SPLITTER = Splitter.on(',');
+    private static final String EQUAL = "=";
+    private static final String COMMA = ",";
+    private static final String COLON = ":";
+    private static final String URI_ENCODING_CHAR_SET = "ISO-8859-1";
+    private static final String URI_NULL_CHECK_ERROR = "uri identifier " +
+            "should not be null";
+    private static final String URI_MODULE_FORMAT = "Illegal URI, First " +
+            "node should be in format \"moduleName:nodeName\"";
+
+    private static final String URI_LEAF_FORMAT = "Illegal URI, List or " +
+            "Leaf-list node should be in format \"nodeName=key\"or " +
+            "\"nodeName=instance-value\"";
+
+    // no instantiation
+    private DefaultCodecUtils() {
+    }
+
+    /**
+     * Converts  URI identifier to YDT builder.
+     *
+     * @param identifier the uri identifier from web request
+     * @param builder    the base YDT builder
+     * @param ydtOpType  the YDT context operation type
+     * @return the YDT builder with the tree info of identifier
+     */
+    public static YdtBuilder convertUriToYdt(
+            String identifier,
+            YdtBuilder builder,
+            YdtContextOperationType ydtOpType) {
+        checkNotNull(identifier, URI_NULL_CHECK_ERROR);
+        List<String> segmentPaths =
+                urlPathArgsDecode(SLASH_SPLITTER.split(identifier));
+        if (segmentPaths.isEmpty()) {
+            return null;
+        }
+        processPathSegments(segmentPaths, builder, ydtOpType);
+        return builder;
+    }
+
+    /**
+     * Returns true, if the list is not null and non-empty; false otherwise.
+     *
+     * @param object list object
+     * @return true, if the list is not null and non-empty; false otherwise
+     */
+    public static boolean isNonEmpty(List object) {
+        return object != null && !object.isEmpty();
+    }
+
+    /**
+     * Converts a list of path segments to a YDT builder tree.
+     *
+     * @param paths     the list of path segments split from URI
+     * @param builder   the base YDT builder
+     * @param ydtOpType the YDT context operation type
+     * @return the YDT builder with the tree info of paths
+     */
+    private static YdtBuilder processPathSegments(
+            List<String> paths,
+            YdtBuilder builder,
+            YdtContextOperationType ydtOpType) {
+        if (paths.isEmpty()) {
+            return builder;
+        }
+        boolean isLastNode = paths.size() == 1;
+        YdtContextOperationType thisOpType = isLastNode ? ydtOpType : NONE;
+
+        final String path = paths.iterator().next();
+        if (path.contains(COLON)) {
+            addModule(builder, path);
+            addNode(path, builder, thisOpType);
+        } else if (path.contains(EQUAL)) {
+            addListOrLeafList(path, builder, thisOpType);
+        } else {
+            addLeaf(path, builder, thisOpType);
+        }
+
+        if (isLastNode) {
+            return builder;
+        }
+        List<String> remainPaths = paths.subList(1, paths.size());
+        processPathSegments(remainPaths, builder, ydtOpType);
+
+        return builder;
+    }
+
+    /**
+     * Returns YDT builder after adding module node.
+     *
+     * @param builder YDT builder
+     * @param path    path segment
+     * @return the YDT builder
+     */
+    private static YdtBuilder addModule(YdtBuilder builder, String path) {
+        String moduleName = getPreSegment(path, COLON);
+        if (moduleName == null) {
+            throw new YchException(URI_MODULE_FORMAT);
+        }
+        builder.addChild(moduleName, null, SINGLE_INSTANCE_NODE);
+        return builder;
+    }
+
+    /**
+     * Returns YDT builder after adding single instance node.
+     *
+     * @param path      path segments
+     * @param builder   YDT builder
+     * @param ydtOpType YDT context operation type
+     * @return the YDT builder
+     */
+    private static YdtBuilder addNode(String path, YdtBuilder builder,
+                                      YdtContextOperationType ydtOpType) {
+        String nodeName = getPostSegment(path, COLON);
+        builder.addChild(nodeName, null, SINGLE_INSTANCE_NODE, ydtOpType);
+        return builder;
+    }
+
+    /**
+     * Returns YDT builder after adding multi instance node.
+     *
+     * @param path    path segments
+     * @param builder YDT builder
+     * @param opType  the YDT context operation type
+     * @return the YDT builder
+     */
+    private static YdtBuilder addListOrLeafList(
+            String path,
+            YdtBuilder builder,
+            YdtContextOperationType opType) {
+        String nodeName = getPreSegment(path, EQUAL);
+        String keyStr = getPostSegment(path, EQUAL);
+        if (keyStr == null) {
+            throw new YchException(URI_LEAF_FORMAT);
+        }
+        builder.setDefaultEditOperationType(opType);
+        if (keyStr.contains(COMMA)) {
+            List<String> keys = Lists.newArrayList(
+                    COMMA_SPLITTER.split(keyStr));
+            builder.addMultiInstanceChild(nodeName, null, keys, null);
+        } else {
+            builder.addMultiInstanceChild(nodeName, null,
+                                          Lists.newArrayList(keyStr), null);
+        }
+        return builder;
+    }
+
+    /**
+     * Returns YDT builder after adding leaf.
+     *
+     * @param path      path segments
+     * @param builder   YDT builder
+     * @param ydtOpType YDT context operation type
+     * @return the YDT builder
+     */
+    private static YdtBuilder addLeaf(String path, YdtBuilder builder,
+                                      YdtContextOperationType ydtOpType) {
+        checkNotNull(path);
+        builder.addChild(path, null, ydtOpType);
+        return builder;
+    }
+
+    /**
+     * Returns the node name before the specified character in the string.
+     *
+     * @param path      path segment
+     * @param splitChar character in the string
+     * @return the node name string
+     */
+    private static String getPreSegment(String path, String splitChar) {
+        int idx = path.indexOf(splitChar);
+        if (idx == -1) {
+            return null;
+        }
+
+        if (path.indexOf(':', idx + 1) != -1) {
+            return null;
+        }
+
+        return path.substring(0, idx);
+    }
+
+    /**
+     * Returns the string after the specified character in the string.
+     *
+     * @param path      path segment
+     * @param splitChar character in the string
+     * @return the substring after specified character
+     */
+    private static String getPostSegment(String path, String splitChar) {
+        int idx = path.indexOf(splitChar);
+        if (idx == -1) {
+            return path;
+        }
+
+        if (path.indexOf(splitChar, idx + 1) != -1) {
+            return null;
+        }
+
+        return path.substring(idx + 1);
+    }
+
+    /**
+     * Converts a list of path from the original format to ISO-8859-1 code.
+     *
+     * @param paths the original paths
+     * @return list of decoded paths
+     */
+    private static List<String> urlPathArgsDecode(Iterable<String> paths) {
+        try {
+            List<String> decodedPathArgs = new ArrayList<>();
+            for (String pathArg : paths) {
+                String decode = URLDecoder.decode(pathArg,
+                                                  URI_ENCODING_CHAR_SET);
+                decodedPathArgs.add(decode);
+            }
+            return decodedPathArgs;
+        } catch (UnsupportedEncodingException e) {
+            throw new YchException("Invalid URL path arg '" + paths + "': ", e);
+        }
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/package-info.java
new file mode 100644
index 0000000..f0d8599
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/utils/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provides implementation of default codec utilities.
+ */
+package org.onosproject.yms.app.ych.defaultcodecs.utils;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodec.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodec.java
new file mode 100644
index 0000000..915863e
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodec.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.onosproject.yms.app.ych.YchException;
+import org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodec;
+import org.onosproject.yms.app.ych.defaultcodecs.utils.DefaultCodecUtils;
+import org.onosproject.yms.app.ydt.DefaultYdtWalker;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedBuilder;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtExtendedWalker;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ych.YangCompositeEncoding;
+import org.onosproject.yms.ych.YangDataTreeCodec;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.util.Map;
+
+import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML;
+import static org.onosproject.yms.ydt.YdtContextOperationType.CREATE;
+
+/**
+ * Represents an implementation of YCH data tree codec interface.
+ */
+public class DefaultXmlCodec implements YangDataTreeCodec {
+
+    private static final String E_RESTCONF_ROOT = "/onos/restconf";
+    private static final String E_YDT_ROOT_NODE = "YDT extended root node " +
+            "is null.";
+    private static final String E_ROOT_ELEMENT = "Root element in XML " +
+            "input string is not well-formed.";
+    private static final String E_ROOT_KEY_ELEMENT = "Root element " +
+            "(filter, config, data) in XML input string is not found.";
+
+
+    /**
+     * Creates a new YANG xml codec.
+     */
+    public DefaultXmlCodec() {
+    }
+
+    /**
+     * Returns the xml string from YDT.
+     *
+     * @param ydtBuilder YDT builder
+     * @return the xml string from YDT
+     */
+    private String buildXmlForYdt(YdtBuilder ydtBuilder) {
+
+        YdtExtendedBuilder extBuilder = (YdtExtendedBuilder) ydtBuilder;
+        YdtExtendedContext rootNode = extBuilder.getRootNode();
+
+        if (rootNode == null) {
+            throw new YchException(E_YDT_ROOT_NODE);
+        }
+
+        // Creating the root element for xml.
+        Element rootElement =
+                DocumentHelper.createDocument().addElement(rootNode.getName());
+
+        // Adding the name space if exist for root name.
+        if (rootNode.getNamespace() != null) {
+            rootElement.add(Namespace.get(rootNode.getNamespace()));
+        }
+
+        // Adding the attribute if exist
+        Map<String, String> tagAttrMap = extBuilder.getRootTagAttributeMap();
+        if (tagAttrMap != null && !tagAttrMap.isEmpty()) {
+            for (Map.Entry<String, String> attr : tagAttrMap.entrySet()) {
+                rootElement.addAttribute(attr.getKey(), attr.getValue());
+            }
+        }
+
+        XmlCodecYdtListener listener = new XmlCodecYdtListener(XML, rootNode);
+        listener.getElementStack().push(rootElement);
+
+        // Walk through YDT and build the xml.
+        YdtExtendedWalker extWalker = new DefaultYdtWalker();
+        extWalker.walk(listener, rootNode);
+
+        return rootElement.asXML();
+    }
+
+    @Override
+    public String encodeYdtToProtocolFormat(YdtBuilder ydtBuilder) {
+        return buildXmlForYdt(ydtBuilder);
+    }
+
+    @Override
+    public YangCompositeEncoding encodeYdtToCompositeProtocolFormat(
+            YdtBuilder ydtBuilder) {
+
+        YangCompositeEncodingImpl encoding = new YangCompositeEncodingImpl();
+        encoding.setResourceIdentifier(null);
+        encoding.setResourceInformation(buildXmlForYdt(ydtBuilder));
+        return encoding;
+    }
+
+    @Override
+    public YdtBuilder decodeCompositeProtocolDataToYdt(
+            YangCompositeEncoding protoData,
+            Object schemaReg,
+            YmsOperationType opType) {
+
+        YdtExtendedBuilder extBuilder =
+                new YangRequestWorkBench(E_RESTCONF_ROOT, null,
+                                         opType,
+                                         (YangSchemaRegistry) schemaReg,
+                                         false);
+
+        DefaultCodecUtils.convertUriToYdt(protoData.getResourceIdentifier(),
+                                          extBuilder,
+                                          CREATE);
+        Document document;
+
+        try {
+            document = DocumentHelper
+                    .parseText(protoData.getResourceInformation());
+        } catch (DocumentException e) {
+            throw new YchException(E_ROOT_ELEMENT);
+        }
+
+        XmlCodecListener listener = new XmlCodecListener();
+        listener.setYdtExtBuilder(extBuilder);
+
+        // Walk through xml and build the yang data tree.
+        XmlWalker walker = new DefaultXmlCodecWalker();
+        walker.walk(listener, document.getRootElement(),
+                    document.getRootElement());
+        return extBuilder;
+    }
+
+    @Override
+    public YdtBuilder decodeProtocolDataToYdt(String protoData,
+                                              Object schemaReg,
+                                              YmsOperationType opType) {
+        Document document;
+
+        try {
+            document = DocumentHelper.parseText(protoData);
+        } catch (DocumentException e) {
+            throw new YchException(E_ROOT_ELEMENT);
+        }
+
+        NetconfCodec codec = new NetconfCodec();
+        // Find the root element in xml string
+        Element rootElement =
+                codec.getDataRootElement(document.getRootElement(), opType);
+
+        if (rootElement == null) {
+            throw new YchException(E_ROOT_KEY_ELEMENT);
+        }
+
+        // Get the YDT builder for the logical root name.
+        YdtExtendedBuilder extBuilder =
+                new YangRequestWorkBench(rootElement.getName(),
+                                         rootElement.getNamespaceURI(),
+                                         opType,
+                                         (YangSchemaRegistry) schemaReg,
+                                         false);
+
+        XmlCodecListener listener = new XmlCodecListener();
+        listener.setYdtExtBuilder(extBuilder);
+        // Walk through xml and build the yang data tree.
+        XmlWalker walker = new DefaultXmlCodecWalker();
+        walker.walk(listener, rootElement, rootElement);
+        return extBuilder;
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java
new file mode 100644
index 0000000..b5a9ea2
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/DefaultXmlCodecWalker.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+
+import static org.onosproject.yms.app.ych.defaultcodecs.xml.XmlNodeType.OBJECT_NODE;
+import static org.onosproject.yms.app.ych.defaultcodecs.xml.XmlNodeType.TEXT_NODE;
+
+/**
+ * Represents implementation of codec xml walker.
+ */
+class DefaultXmlCodecWalker implements XmlWalker {
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Override
+    public void walk(XmlListener listener, Element element,
+                     Element rootElement) {
+        try {
+            listener.enterXmlElement(element, getElementType(element),
+                                     rootElement);
+
+            if (element.hasContent() && !element.isTextOnly()) {
+                for (Iterator i = element.elementIterator(); i.hasNext();) {
+                    Element childElement = (Element) i.next();
+                    walk(listener, childElement, rootElement);
+                }
+            }
+
+            listener.exitXmlElement(element, getElementType(element),
+                                    rootElement);
+        } catch (Exception e) {
+            log.error("Exception occurred when walk xml element: {}", element);
+        }
+    }
+
+    /**
+     * Determine the type of an element.
+     *
+     * @param element to be analysed
+     * @return type of the element
+     */
+    private XmlNodeType getElementType(Element element) {
+        return element.hasContent() && element.isTextOnly() ?
+                TEXT_NODE : OBJECT_NODE;
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecHandler.java
new file mode 100644
index 0000000..b7685a8
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecHandler.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.util.Stack;
+
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.OPERATION;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+
+/**
+ * Represents an codec handler to process the xml content and add
+ * element to the stack.
+ */
+public abstract class XmlCodecHandler {
+
+    /**
+     * Sets the namespace and tag name in element tree maintained in stack.
+     *
+     * @param ydtContext   YDT context
+     * @param elementStack element tree stack
+     */
+    void processXmlContext(YdtContext ydtContext,
+                           Stack<Element> elementStack) {
+
+        Element newElement = updateNameAndNamespace(ydtContext,
+                                                    elementStack.peek());
+        elementStack.push(newElement);
+    }
+
+    /**
+     * Returns the new element name by updating tag name and namespace.
+     *
+     * @param ydtContext YDT context node
+     * @param xmlElement element in the stack used for adding new element
+     * @return new element name by updating tag name and namespace
+     */
+    Element updateNameAndNamespace(YdtContext ydtContext,
+                                   Element xmlElement) {
+        String nameSpace = null;
+        if (ydtContext.getNamespace() != null) {
+            nameSpace = ydtContext.getNamespace();
+        }
+
+        String parentNameSpace = null;
+        if (ydtContext.getParent() != null) {
+            parentNameSpace = ydtContext.getParent().getNamespace();
+        }
+
+        Element newElement;
+        if (nameSpace != null) {
+            newElement = xmlElement.addElement(ydtContext.getName(),
+                                               nameSpace);
+        } else {
+            if (parentNameSpace != null) {
+                newElement = xmlElement.addElement(ydtContext.getName(),
+                                                   parentNameSpace);
+            } else {
+                newElement = xmlElement.addElement(ydtContext.getName());
+            }
+        }
+
+        YdtContextOperationType opType = ((YdtExtendedContext) ydtContext)
+                .getYdtContextOperationType();
+        if (opType != null && opType != NONE) {
+            newElement.addAttribute(OPERATION,
+                                    opType.toString().toLowerCase());
+        }
+
+        return newElement;
+    }
+
+    /**
+     * Sets the leaf value in the current element maintained in stack.
+     * Default behaviour is to do nothing.
+     *
+     * @param ydtContext      YDT context node
+     * @param domElementStack current element node in the stack
+     */
+    public void setXmlValue(YdtContext ydtContext,
+                            Stack<Element> domElementStack) {
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java
new file mode 100644
index 0000000..6b6ba38
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecListener.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Attribute;
+import org.dom4j.Element;
+import org.onosproject.yms.app.ydt.YdtExtendedBuilder;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.util.Iterator;
+
+import static org.onosproject.yms.app.ych.defaultcodecs.netconf.NetconfCodecConstants.OPERATION;
+import static org.onosproject.yms.app.ych.defaultcodecs.xml.XmlNodeType.OBJECT_NODE;
+import static org.onosproject.yms.app.ych.defaultcodecs.xml.XmlNodeType.TEXT_NODE;
+
+/**
+ * Default implementation of codec xml listener.
+ */
+class XmlCodecListener implements XmlListener {
+
+    /**
+     * YANG data tree builder object.
+     */
+    private YdtExtendedBuilder ydtExtBuilder;
+
+    /**
+     * Sets the YANG data tree builder object.
+     *
+     * @param ydtBuilder YANG data tree builder object
+     */
+    void setYdtExtBuilder(YdtExtendedBuilder ydtBuilder) {
+        ydtExtBuilder = ydtBuilder;
+    }
+
+    @Override
+    public void enterXmlElement(Element element, XmlNodeType nodeType,
+                                Element rootElement) {
+        if (element.equals(rootElement)) {
+            return;
+        }
+
+        YdtContextOperationType opType = null;
+
+        for (Iterator iter = element.attributeIterator(); iter.hasNext();) {
+            Attribute attr = (Attribute) iter.next();
+            if (attr.getName().equals(OPERATION)) {
+                opType =
+                        YdtContextOperationType.valueOf(attr.getValue()
+                                                                .toUpperCase());
+            }
+        }
+
+        String nameSpace = null;
+        if (element.getNamespace() != null) {
+            nameSpace = element.getNamespace().getURI();
+        }
+
+        if (nodeType == OBJECT_NODE) {
+            if (ydtExtBuilder != null) {
+                ydtExtBuilder.addChild(element.getName(), nameSpace, opType);
+            }
+        } else if (nodeType == TEXT_NODE) {
+
+            if (ydtExtBuilder != null) {
+                ydtExtBuilder.addLeaf(element.getName(), nameSpace,
+                                      element.getText());
+            }
+        }
+    }
+
+    @Override
+    public void exitXmlElement(Element element, XmlNodeType nodeType,
+                               Element rootElement) {
+        if (element.equals(rootElement)) {
+            return;
+        }
+
+        if (ydtExtBuilder != null) {
+            ydtExtBuilder.traverseToParent();
+        }
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceHandler.java
new file mode 100644
index 0000000..fa63ce5
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceHandler.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+/**
+ * Represents a multi instance node handler in YCH.
+ */
+public class XmlCodecMultiInstanceHandler extends XmlCodecHandler {
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceLeafHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceLeafHandler.java
new file mode 100644
index 0000000..234d9d9
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecMultiInstanceLeafHandler.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.Iterator;
+import java.util.Stack;
+
+/**
+ * Represents a multi instance leaf node handler in YCH.
+ */
+public class XmlCodecMultiInstanceLeafHandler extends XmlCodecHandler {
+
+    @Override
+    public void setXmlValue(YdtContext ydtContext,
+                            Stack<Element> elementStack) {
+
+        if (ydtContext.getValueSet().isEmpty()) {
+            return;
+        }
+
+        Iterator<String> iterator = ydtContext.getValueSet().iterator();
+        elementStack.peek().setText(iterator.next());
+        Element topOfStack = elementStack.pop();
+        Element parent = elementStack.peek();
+
+        while (iterator.hasNext()) {
+            Element newElement = updateNameAndNamespace(ydtContext, parent);
+            newElement.setText(iterator.next());
+        }
+        elementStack.push(topOfStack);
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceHandler.java
new file mode 100644
index 0000000..66f3483
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceHandler.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+/**
+ * Represents a single instance node handler in YCH.
+ */
+public class XmlCodecSingleInstanceHandler extends XmlCodecHandler {
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceLeafHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceLeafHandler.java
new file mode 100644
index 0000000..f44f9b2
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecSingleInstanceLeafHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.Stack;
+
+/**
+ * Represents a single instance leaf node handler in YCH.
+ */
+public class XmlCodecSingleInstanceLeafHandler extends XmlCodecHandler {
+
+    @Override
+    public void setXmlValue(YdtContext ydtContext,
+                            Stack<Element> elementStack) {
+        elementStack.peek().setText(ydtContext.getValue());
+    }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecYdtListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecYdtListener.java
new file mode 100644
index 0000000..98a8ccb
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlCodecYdtListener.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+import org.onosproject.yms.app.ych.defaultcodecs.CodecHandlerFactory;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtExtendedListener;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.Objects;
+import java.util.Stack;
+
+import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML;
+
+/**
+ * Represents implementation of codec YANG data object listener.
+ */
+class XmlCodecYdtListener implements YdtExtendedListener {
+
+    /**
+     * Data format type requested from driver.
+     */
+    private YangProtocolEncodingFormat dataFormat;
+
+    /**
+     * Stack for element is maintained for hierarchical references, this is
+     * used during YDT walker and preparation of xml/json.
+     */
+    private final Stack<Element> elementStack = new Stack<>();
+
+    /**
+     * Root name received from driver.
+     */
+    private YdtExtendedContext rootYdtNode;
+
+    /**
+     * Creates a new codec listener.
+     *
+     * @param format   protocol data format
+     * @param rootNode extended YDT root node
+     */
+    XmlCodecYdtListener(YangProtocolEncodingFormat format,
+                        YdtExtendedContext rootNode) {
+        dataFormat = format;
+        rootYdtNode = rootNode;
+    }
+
+    /**
+     * Returns the stack for the element.
+     *
+     * @return the stack for the element
+     */
+    Stack<Element> getElementStack() {
+        return elementStack;
+    }
+
+    @Override
+    public void enterYdtNode(YdtExtendedContext ydtContext) {
+
+        if (!Objects.equals(rootYdtNode, ydtContext)) {
+
+            CodecHandlerFactory factory = CodecHandlerFactory.instance();
+            XmlCodecHandler handler =
+                    factory.getCodecHandlerForContext(ydtContext, dataFormat);
+            try {
+                if (dataFormat == XML && handler != null) {
+                    handler.processXmlContext(ydtContext, elementStack);
+                }
+            } catch (Exception e) {
+                // TODO
+            }
+
+            if (dataFormat == XML && handler != null) {
+                handler.setXmlValue(ydtContext, elementStack);
+            }
+        }
+    }
+
+    @Override
+    public void exitYdtNode(YdtExtendedContext ydtExtendedContext) {
+        if (!Objects.equals(rootYdtNode, ydtExtendedContext)) {
+            elementStack.pop();
+        }
+    }
+
+    @Override
+    public void enterYdtNode(YdtContext ydtContext) {
+    }
+
+    @Override
+    public void exitYdtNode(YdtContext ydtContext) {
+    }
+
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlListener.java
new file mode 100644
index 0000000..8c1bc7f
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlListener.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provide call back methods which are called
+ * by xml walker while walking the xml data tree. This interface needs to be
+ * implemented by protocol implementing listener's based call backs while
+ * xml walk.
+ */
+interface XmlListener {
+
+    /**
+     * Callback invoked during a node entry. All the related information
+     * about the node can be obtained from the element.
+     *
+     * @param element     current xml node(element)
+     * @param nodeType    xml node type
+     * @param rootElement root element
+     */
+    void enterXmlElement(Element element, XmlNodeType nodeType,
+                         Element rootElement);
+
+    /**
+     * Callback invoked during a node exit. All the related information
+     * about the node can be obtained from the element.
+     *
+     * @param element     current xml node(element)
+     * @param nodeType    xml node type
+     * @param rootElement root element
+     */
+    void exitXmlElement(Element element, XmlNodeType nodeType,
+                        Element rootElement);
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlNodeType.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlNodeType.java
new file mode 100644
index 0000000..786f1b5
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlNodeType.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+/**
+ * Represents type of node in xml data tree.
+ */
+enum XmlNodeType {
+    /**
+     * An object node has at least one child node.
+     */
+    OBJECT_NODE,
+
+    /**
+     * A text node has no child node, and has a text value.
+     */
+    TEXT_NODE
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlWalker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlWalker.java
new file mode 100644
index 0000000..9e48add
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/XmlWalker.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.dom4j.Element;
+
+/**
+ * Abstraction of an entity which provides interfaces for xml walk.
+ * This interface serve as common tools for anyone who needs to parse the xml
+ * node with depth-first algorithm.
+ */
+interface XmlWalker {
+    /**
+     * Walks the xml data tree. Protocols implements xml listener service
+     * and walks xml tree with input as implemented object. xml walker provides
+     * call backs to implemented methods.
+     *
+     * @param listener    xml listener implemented by the protocol
+     * @param walkElement root node(element) of the xml data tree
+     * @param rootElement logical root node(element) of the xml data tree
+     */
+    void walk(XmlListener listener, Element walkElement, Element rootElement);
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/YangCompositeEncodingImpl.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/YangCompositeEncodingImpl.java
new file mode 100644
index 0000000..0e8d669
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/YangCompositeEncodingImpl.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
+
+import org.onosproject.yms.ych.YangCompositeEncoding;
+import org.onosproject.yms.ych.YangResourceIdentifierType;
+
+/**
+ * Represents implementation of YangCompositeEncoding interfaces.
+ */
+class YangCompositeEncodingImpl implements YangCompositeEncoding {
+
+    /**
+     * Resource identifier for composite encoding.
+     */
+    private String resourceIdentifier;
+
+    /**
+     * Resource information for composite encoding.
+     */
+    private String resourceInformation;
+
+    /**
+     * Resource identifier type.
+     */
+    private YangResourceIdentifierType resourceIdentifierType;
+
+    @Override
+    public void setResourceIdentifier(String resourceId) {
+        resourceIdentifier = resourceId;
+    }
+
+    @Override
+    public void setResourceInformation(String resourceInfo) {
+        resourceInformation = resourceInfo;
+    }
+
+    @Override
+    public void setResourceIdentifierType(YangResourceIdentifierType idType) {
+        resourceIdentifierType = idType;
+    }
+
+    @Override
+    public String getResourceIdentifier() {
+        return resourceIdentifier;
+    }
+
+    @Override
+    public YangResourceIdentifierType getResourceIdentifierType() {
+        return resourceIdentifierType;
+    }
+
+    @Override
+    public String getResourceInformation() {
+        return resourceInformation;
+    }
+}
+
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/package-info.java
new file mode 100644
index 0000000..68e96e6
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/defaultcodecs/xml/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provides implementation of default codec handler for xml related
+ * operation.
+ */
+package org.onosproject.yms.app.ych.defaultcodecs.xml;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/package-info.java
new file mode 100644
index 0000000..0cf839b
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ych/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provides interfaces to YANG codec utility.
+ * YANG codec utility provides interfaces which can be used by the driver / provider to
+ * translate protocol specific data representation to YANG modeled objects.
+ */
+package org.onosproject.yms.app.ych;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
index ba0554b..4ccce37 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
@@ -26,6 +26,8 @@
 import org.onosproject.core.CoreService;
 import org.onosproject.core.IdGenerator;
 import org.onosproject.yms.app.yab.YangApplicationBroker;
+import org.onosproject.yms.app.ych.DefaultYangCodecHandler;
+import org.onosproject.yms.app.ych.defaultcodecs.YangCodecRegistry;
 import org.onosproject.yms.app.ydt.DefaultYdtWalker;
 import org.onosproject.yms.app.ydt.YangRequestWorkBench;
 import org.onosproject.yms.app.ynh.YangNotificationExtendedService;
@@ -84,6 +86,10 @@
                 Executors.newSingleThreadExecutor(groupedThreads(
                         "onos/apps/yang-management-system/schema-registry",
                         "schema-registry-handler", log));
+
+        //Initilize the default codecs
+        YangCodecRegistry.initializeDefaultCodec();
+
         log.info("Started");
     }
 
@@ -174,9 +180,8 @@
     }
 
     @Override
-    public void registerDefaultCodec(YangDataTreeCodec defaultCodec,
-                                     YangProtocolEncodingFormat dataFormat) {
-
+    public void registerDefaultCodec(YangDataTreeCodec defaultCodec, YangProtocolEncodingFormat dataFormat) {
+        YangCodecRegistry.registerDefaultCodec(defaultCodec, dataFormat);
     }
 
     @Override
@@ -196,7 +201,11 @@
 
     @Override
     public YangCodecHandler getYangCodecHandler() {
-        return null;
+
+        YangSchemaRegistry yangSchemaRegistry =
+                new DefaultYangSchemaRegistry(
+                        String.valueOf(moduleIdGenerator.getNewId()));
+        return new DefaultYangCodecHandler(yangSchemaRegistry);
     }
 
     /**