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.transaction.ShardTransactionMessages;
14 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 public class MergeData extends ModifyData{
19 public MergeData(InstanceIdentifier path, NormalizedNode<?, ?> data,
20 SchemaContext context) {
21 super(path, data, context);
24 @Override public Object toSerializable() {
25 return ShardTransactionMessages.MergeData.newBuilder()
26 .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.getParentPath(path.toString()))
27 .setNormalizedNode(new NormalizedNodeToNodeCodec(schemaContext).encode(path, data).getNormalizedNode()).build();
30 public static MergeData fromSerializable(Object serializable, SchemaContext schemaContext){
31 ShardTransactionMessages.MergeData o = (ShardTransactionMessages.MergeData) serializable;
32 InstanceIdentifier identifier = InstanceIdentifierUtils.from(o.getInstanceIdentifierPathArguments());
34 NormalizedNode<?, ?> normalizedNode =
35 new NormalizedNodeToNodeCodec(schemaContext)
36 .decode(identifier, o.getNormalizedNode());
38 return new MergeData(identifier, normalizedNode, schemaContext);