2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.netconf.topology.singleton.messages;
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;
21 public class SchemaPathMessage implements Serializable {
22 private static final long serialVersionUID = 1L;
24 @SuppressFBWarnings("SE_BAD_FIELD")
25 private final SchemaPath schemaPath;
27 public SchemaPathMessage(final SchemaPath schemaPath) {
28 this.schemaPath = schemaPath;
31 public SchemaPath getSchemaPath() {
35 private Object writeReplace() {
36 return new Proxy(this);
40 public String toString() {
41 return "SchemaPathMessage [schemaPath=" + schemaPath + "]";
44 private static class Proxy implements Externalizable {
45 private static final long serialVersionUID = 2L;
47 private SchemaPathMessage schemaPathMessage;
49 @SuppressWarnings("checkstyle:RedundantModifier")
51 //due to Externalizable
54 Proxy(final SchemaPathMessage schemaPathMessage) {
55 this.schemaPathMessage = schemaPathMessage;
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);
67 out.writeBoolean(schemaPathMessage.getSchemaPath().isAbsolute());
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();
78 final boolean absolute = in.readBoolean();
79 schemaPathMessage = new SchemaPathMessage(SchemaPath.create(absolute, paths));
82 private Object readResolve() {
83 return schemaPathMessage;