Teach NETCONF about YANG 1.1 actions in cluster topology
[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 com.google.common.collect.Iterables;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import java.io.Serializable;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20
21 public class SchemaPathMessage implements Serializable {
22     private static final long serialVersionUID = 1L;
23
24     @SuppressFBWarnings("SE_BAD_FIELD")
25     private final SchemaPath schemaPath;
26
27     public SchemaPathMessage(final SchemaPath schemaPath) {
28         this.schemaPath = schemaPath;
29     }
30
31     public SchemaPath getSchemaPath() {
32         return schemaPath;
33     }
34
35     private Object writeReplace() {
36         return new Proxy(this);
37     }
38
39     @Override
40     public String toString() {
41         return "SchemaPathMessage [schemaPath=" + schemaPath + "]";
42     }
43
44     private static class Proxy implements Externalizable {
45         private static final long serialVersionUID = 2L;
46
47         private SchemaPathMessage schemaPathMessage;
48
49         @SuppressWarnings("checkstyle:RedundantModifier")
50         public Proxy() {
51             //due to Externalizable
52         }
53
54         Proxy(final SchemaPathMessage schemaPathMessage) {
55             this.schemaPathMessage = schemaPathMessage;
56         }
57
58         @Override
59         public void writeExternal(final ObjectOutput out) throws IOException {
60             final Iterable<QName> path = schemaPathMessage.getSchemaPath().getPathFromRoot();
61             out.writeInt(Iterables.size(path));
62             for (final QName qualifiedName : path) {
63                 // FIXME: switch to QName.writeTo() or a sal-clustering-commons stream
64                 out.writeObject(qualifiedName);
65             }
66
67             out.writeBoolean(schemaPathMessage.getSchemaPath().isAbsolute());
68         }
69
70         @Override
71         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
72             final int sizePath = in.readInt();
73             final QName[] paths = new QName[sizePath];
74             for (int i = 0; i < sizePath; i++) {
75                 // FIXME: switch to QName.readFrom() or a sal-clustering-commons stream
76                 paths[i] = (QName) in.readObject();
77             }
78             final boolean absolute = in.readBoolean();
79             schemaPathMessage = new SchemaPathMessage(SchemaPath.create(absolute, paths));
80         }
81
82         private Object readResolve() {
83             return schemaPathMessage;
84         }
85     }
86
87 }