BUG 2412 - restconf @GET getModule(identifier,uri) method migration
[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
21 /**
22  * DeleteModification store all the parameters required to delete a path from the data tree
23  */
24 public class DeleteModification extends AbstractModification {
25     private static final long serialVersionUID = 1L;
26
27     public DeleteModification() {
28     }
29
30     public DeleteModification(YangInstanceIdentifier path) {
31         super(path);
32     }
33
34     @Override
35     public void apply(DOMStoreWriteTransaction transaction) {
36         transaction.delete(getPath());
37     }
38
39     @Override
40     public byte getType() {
41         return DELETE;
42     }
43
44     @Override
45     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
46         in.readShort();
47         setPath(SerializationUtils.deserializePath(in));
48     }
49
50     @Override
51     public void writeExternal(ObjectOutput out) throws IOException {
52         out.writeShort(DataStoreVersions.CURRENT_VERSION);
53         SerializationUtils.serializePath(getPath(), out);
54     }
55
56     @Override
57     @Deprecated
58     public Object toSerializable() {
59         return PersistentMessages.Modification.newBuilder().setType(this.getClass().toString())
60                 .setPath(InstanceIdentifierUtils.toSerializable(getPath())).build();
61     }
62
63     @Deprecated
64     public static DeleteModification fromSerializable(Object serializable) {
65         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
66         return new DeleteModification(InstanceIdentifierUtils.fromSerializable(o.getPath()));
67     }
68
69     public static DeleteModification fromStream(ObjectInput in) throws ClassNotFoundException, IOException {
70         DeleteModification mod = new DeleteModification();
71         mod.readExternal(in);
72         return mod;
73     }
74 }