Merge "Fix the build errors due to the class change of InstanceIdentifier to YangInst...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / ReadDataReply.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.protobuff.messages.transaction.ShardTransactionMessages;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
17 public class ReadDataReply implements SerializableMessage{
18   private final NormalizedNode<?, ?> normalizedNode;
19   private final SchemaContext schemaContext;
20   public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.ReadDataReply.class;
21   public ReadDataReply(SchemaContext context,NormalizedNode<?, ?> normalizedNode){
22
23     this.normalizedNode = normalizedNode;
24     this.schemaContext = context;
25   }
26
27   public NormalizedNode<?, ?> getNormalizedNode() {
28     return normalizedNode;
29   }
30
31   public Object toSerializable(){
32     if(normalizedNode != null) {
33       return ShardTransactionMessages.ReadDataReply.newBuilder()
34           .setNormalizedNode(new NormalizedNodeToNodeCodec(schemaContext)
35                   .encode(InstanceIdentifier.builder().build(), normalizedNode).getNormalizedNode()
36           ).build();
37     }else{
38       return ShardTransactionMessages.ReadDataReply.newBuilder().build();
39
40     }
41
42   }
43
44   public static ReadDataReply fromSerializable(SchemaContext schemaContext,InstanceIdentifier id,Object serializable){
45     ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
46     return new ReadDataReply(schemaContext,new NormalizedNodeToNodeCodec(schemaContext).decode(id, o.getNormalizedNode()));
47   }
48 }