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
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import com.google.protobuf.ByteString;
12 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
13 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 public class ReadDataReply implements SerializableMessage {
19 public static final Class<ShardTransactionMessages.ReadDataReply> SERIALIZABLE_CLASS =
20 ShardTransactionMessages.ReadDataReply.class;
22 private final NormalizedNode<?, ?> normalizedNode;
23 private final SchemaContext schemaContext;
25 public ReadDataReply(SchemaContext context,NormalizedNode<?, ?> normalizedNode){
27 this.normalizedNode = normalizedNode;
28 this.schemaContext = context;
31 public NormalizedNode<?, ?> getNormalizedNode() {
32 return normalizedNode;
36 public Object toSerializable(){
37 if(normalizedNode != null) {
38 return ShardTransactionMessages.ReadDataReply.newBuilder()
39 .setNormalizedNode(new NormalizedNodeToNodeCodec(schemaContext)
40 .encode(normalizedNode).getNormalizedNode()).build();
42 return ShardTransactionMessages.ReadDataReply.newBuilder().build();
47 public static ReadDataReply fromSerializable(SchemaContext schemaContext,
48 YangInstanceIdentifier id, Object serializable) {
49 ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
50 return new ReadDataReply(schemaContext, new NormalizedNodeToNodeCodec(schemaContext).decode(
51 o.getNormalizedNode()));
54 public static ByteString getNormalizedNodeByteString(Object serializable){
55 ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
56 return ((ShardTransactionMessages.ReadDataReply) serializable).getNormalizedNode().toByteString();