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.modification;
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.persistent.PersistentMessages;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 * WriteModification stores all the parameters required to write data to the specified path
23 public class WriteModification extends AbstractModification {
25 private final NormalizedNode data;
26 private final SchemaContext schemaContext;
28 public WriteModification(YangInstanceIdentifier path, NormalizedNode data, SchemaContext schemaContext) {
31 this.schemaContext = schemaContext;
35 public void apply(DOMStoreWriteTransaction transaction) {
36 transaction.write(path, data);
39 @Override public Object toSerializable() {
40 NormalizedNodeMessages.Container encode =
41 new NormalizedNodeToNodeCodec(schemaContext).encode(
45 return PersistentMessages.Modification.newBuilder()
46 .setType(this.getClass().toString())
47 .setPath(InstanceIdentifierUtils.toSerializable(this.path))
48 .setData(encode.getNormalizedNode())
53 public static WriteModification fromSerializable(
55 SchemaContext schemaContext) {
56 PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
58 YangInstanceIdentifier path = InstanceIdentifierUtils.fromSerializable(o.getPath());
59 NormalizedNode data = new NormalizedNodeToNodeCodec(schemaContext).decode(
62 return new WriteModification(path, data, schemaContext);