Move byte-based serialization method
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModification.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.modification;
10
11 import java.io.ObjectInput;
12 import java.io.ObjectOutput;
13 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
14 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
15 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
18
19 /**
20  * DeleteModification store all the parameters required to delete a path from the data tree.
21  */
22 public class DeleteModification extends AbstractModification {
23     private static final long serialVersionUID = 1L;
24
25     public DeleteModification() {
26         this(DataStoreVersions.CURRENT_VERSION);
27     }
28
29     public DeleteModification(short version) {
30         super(version);
31     }
32
33     public DeleteModification(YangInstanceIdentifier path) {
34         super(path);
35     }
36
37     @Override
38     public void apply(DOMStoreWriteTransaction transaction) {
39         transaction.delete(getPath());
40     }
41
42     @Override
43     public void apply(DataTreeModification transaction) {
44         transaction.delete(getPath());
45     }
46
47     @Override
48     public byte getType() {
49         return DELETE;
50     }
51
52     @Override
53     public void readExternal(ObjectInput in) {
54         setPath(SerializationUtils.deserializePath(in));
55     }
56
57     @Override
58     public void writeExternal(ObjectOutput out) {
59         SerializationUtils.serializePath(getPath(), out);
60     }
61
62     public static DeleteModification fromStream(ObjectInput in, short version) {
63         DeleteModification mod = new DeleteModification(version);
64         mod.readExternal(in);
65         return mod;
66     }
67 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.