Bug 8153: Enforce check-style rules for netconf - netconf-topology-singleton
[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 java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.Serializable;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19
20 public class SchemaPathMessage implements Serializable {
21     private static final long serialVersionUID = 1L;
22
23     private SchemaPath schemaPath;
24
25     public SchemaPathMessage(final SchemaPath schemaPath) {
26         this.schemaPath = schemaPath;
27     }
28
29     public SchemaPath getSchemaPath() {
30         return schemaPath;
31     }
32
33     private Object writeReplace() {
34         return new Proxy(this);
35     }
36
37     private static class Proxy implements Externalizable {
38         private static final long serialVersionUID = 2L;
39
40         private SchemaPathMessage schemaPathMessage;
41
42         Proxy() {
43             //due to Externalizable
44         }
45
46         Proxy(final SchemaPathMessage schemaPathMessage) {
47             this.schemaPathMessage = schemaPathMessage;
48         }
49
50         @Override
51         public void writeExternal(final ObjectOutput out) throws IOException {
52             out.writeInt(Iterables.size(schemaPathMessage.getSchemaPath().getPathTowardsRoot()));
53
54             for (final QName qualifiedName : schemaPathMessage.getSchemaPath().getPathTowardsRoot()) {
55                 out.writeObject(qualifiedName);
56             }
57
58             out.writeBoolean(schemaPathMessage.getSchemaPath().isAbsolute());
59         }
60
61         @Override
62         public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
63             final int sizePath = in.readInt();
64             final QName[] paths = new QName[sizePath];
65             for (int i = 0; i < sizePath; i++) {
66                 paths[i] = (QName) in.readObject();
67             }
68             final boolean absolute = in.readBoolean();
69             schemaPathMessage = new SchemaPathMessage(SchemaPath.create(absolute, paths));
70         }
71
72         private Object readResolve() {
73             return schemaPathMessage;
74         }
75     }
76
77 }