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 java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
16 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils.Applier;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
23 * WriteModification stores all the parameters required to write data to the specified path
25 public class WriteModification extends AbstractModification {
26 private static final long serialVersionUID = 1L;
28 private NormalizedNode<?, ?> data;
30 public WriteModification() {
31 this(DataStoreVersions.CURRENT_VERSION);
34 public WriteModification(short version) {
38 public WriteModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
44 public void apply(final DOMStoreWriteTransaction transaction) {
45 transaction.write(getPath(), data);
49 public void apply(final DataTreeModification transaction) {
50 transaction.write(getPath(), data);
53 public NormalizedNode<?, ?> getData() {
58 public byte getType() {
63 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
64 SerializationUtils.deserializePathAndNode(in, this, APPLIER);
68 public void writeExternal(ObjectOutput out) throws IOException {
69 SerializationUtils.serializePathAndNode(getPath(), data, out);
72 public static WriteModification fromStream(ObjectInput in, short version)
73 throws ClassNotFoundException, IOException {
74 WriteModification mod = new WriteModification(version);
79 private static final Applier<WriteModification> APPLIER = new Applier<WriteModification>() {
81 public void apply(WriteModification instance, YangInstanceIdentifier path,
82 NormalizedNode<?, ?> node) {
83 instance.setPath(path);