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 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;
19 public class WriteData extends ModifyData{
21 public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.WriteData.class;
23 public WriteData(YangInstanceIdentifier path, NormalizedNode<?, ?> data, SchemaContext schemaContext) {
24 super(path, data, schemaContext);
27 @Override public Object toSerializable() {
29 NormalizedNodeMessages.Node normalizedNode =
30 new NormalizedNodeToNodeCodec(schemaContext).encode(path, data)
32 return ShardTransactionMessages.WriteData.newBuilder()
33 .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(path))
34 .setNormalizedNode(normalizedNode).build();
38 public static WriteData fromSerializable(Object serializable, SchemaContext schemaContext){
39 ShardTransactionMessages.WriteData o = (ShardTransactionMessages.WriteData) serializable;
40 YangInstanceIdentifier identifier = InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments());
42 NormalizedNode<?, ?> normalizedNode =
43 new NormalizedNodeToNodeCodec(schemaContext)
44 .decode(identifier, o.getNormalizedNode());
46 return new WriteData(identifier, normalizedNode, schemaContext);