Merge "Add missing copyright text"
[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.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.util.InstanceIdentifierUtils;
16 import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils;
17 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
21
22 /**
23  * DeleteModification store all the parameters required to delete a path from the data tree
24  */
25 public class DeleteModification extends AbstractModification {
26     private static final long serialVersionUID = 1L;
27
28     public DeleteModification() {
29         this(DataStoreVersions.CURRENT_VERSION);
30     }
31
32     public DeleteModification(short version) {
33         super(version);
34     }
35
36     public DeleteModification(YangInstanceIdentifier path) {
37         super(path);
38     }
39
40     @Override
41     public void apply(DOMStoreWriteTransaction transaction) {
42         transaction.delete(getPath());
43     }
44
45     @Override
46     public void apply(DataTreeModification transaction) {
47         transaction.delete(getPath());
48     }
49
50     @Override
51     public byte getType() {
52         return DELETE;
53     }
54
55     @Override
56     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
57         setPath(SerializationUtils.deserializePath(in));
58     }
59
60     @Override
61     public void writeExternal(ObjectOutput out) throws IOException {
62         SerializationUtils.serializePath(getPath(), out);
63     }
64
65     @Override
66     @Deprecated
67     public Object toSerializable() {
68         return PersistentMessages.Modification.newBuilder().setType(this.getClass().toString())
69                 .setPath(InstanceIdentifierUtils.toSerializable(getPath())).build();
70     }
71
72     @Deprecated
73     public static DeleteModification fromSerializable(Object serializable) {
74         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
75         return new DeleteModification(InstanceIdentifierUtils.fromSerializable(o.getPath()));
76     }
77
78     public static DeleteModification fromStream(ObjectInput in, short version)
79             throws ClassNotFoundException, IOException {
80         DeleteModification mod = new DeleteModification(version);
81         mod.readExternal(in);
82         return mod;
83     }
84 }