Merge "Fixed for bug : 1171 - issue while creating subnet"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / MergeData.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
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
12 import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
13 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
14 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 public class MergeData extends ModifyData{
20
21     public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.MergeData.class;
22
23     public MergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data,
24         SchemaContext context) {
25         super(path, data, context);
26     }
27
28     @Override public Object toSerializable() {
29
30         NormalizedNodeMessages.Node normalizedNode =
31             new NormalizedNodeToNodeCodec(schemaContext).encode(path, data)
32                 .getNormalizedNode();
33         return ShardTransactionMessages.MergeData.newBuilder()
34             .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(path))
35             .setNormalizedNode(normalizedNode).build();
36     }
37
38     public static MergeData fromSerializable(Object serializable, SchemaContext schemaContext){
39         ShardTransactionMessages.MergeData o = (ShardTransactionMessages.MergeData) serializable;
40         YangInstanceIdentifier identifier = InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments());
41
42         NormalizedNode<?, ?> normalizedNode =
43             new NormalizedNodeToNodeCodec(schemaContext)
44                 .decode(identifier, o.getNormalizedNode());
45
46         return new MergeData(identifier, normalizedNode, schemaContext);
47     }
48 }