Add changed-leaf-nodes-only subscription extension
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / messages / SchemaPathMessage.java
1 /*
2  * Copyright (c) 2016 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.netconf.topology.singleton.messages;
10
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.InvalidObjectException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import java.io.Serializable;
18 import java.util.List;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21
22 public class SchemaPathMessage implements Serializable {
23     private static final long serialVersionUID = 1L;
24
25     @SuppressFBWarnings("SE_BAD_FIELD")
26     private final Absolute schemaPath;
27
28     public SchemaPathMessage(final QName qname) {
29         this(Absolute.of(qname));
30     }
31
32     public SchemaPathMessage(final Absolute schemaPath) {
33         this.schemaPath = schemaPath;
34     }
35
36     public Absolute getSchemaPath() {
37         return schemaPath;
38     }
39
40     private Object writeReplace() {
41         return new Proxy(this);
42     }
43
44     @Override
45     public String toString() {
46         return "SchemaPathMessage [schemaPath=" + schemaPath + "]";
47     }
48
49     private static class Proxy implements Externalizable {
50         private static final long serialVersionUID = 2L;
51
52         private SchemaPathMessage schemaPathMessage;
53
54         @SuppressWarnings("checkstyle:RedundantModifier")
55         public Proxy() {
56             //due to Externalizable
57         }
58
59         Proxy(final SchemaPathMessage schemaPathMessage) {
60             this.schemaPathMessage = schemaPathMessage;
61         }
62
63         @Override
64         public void writeExternal(final ObjectOutput out) throws IOException {
65             final List<QName> path = schemaPathMessage.getSchemaPath().getNodeIdentifiers();
66             out.writeInt(path.size());
67             for (final QName qualifiedName : path) {
68                 // FIXME: switch to QName.writeTo() or a sal-clustering-commons stream
69                 out.writeObject(qualifiedName);
70             }
71
72             out.writeBoolean(true);
73         }
74
75         @Override
76         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
77             final int sizePath = in.readInt();
78             final QName[] paths = new QName[sizePath];
79             for (int i = 0; i < sizePath; i++) {
80                 // FIXME: switch to QName.readFrom() or a sal-clustering-commons stream
81                 paths[i] = (QName) in.readObject();
82             }
83             final boolean absolute = in.readBoolean();
84             if (!absolute) {
85                 throw new InvalidObjectException("Non-absolute path");
86             }
87             schemaPathMessage = new SchemaPathMessage(Absolute.of(paths));
88         }
89
90         private Object readResolve() {
91             return schemaPathMessage;
92         }
93     }
94
95 }