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 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;
22 public class SchemaPathMessage implements Serializable {
23 private static final long serialVersionUID = 1L;
25 @SuppressFBWarnings("SE_BAD_FIELD")
26 private final Absolute schemaPath;
28 public SchemaPathMessage(final QName qname) {
29 this(Absolute.of(qname));
32 public SchemaPathMessage(final Absolute schemaPath) {
33 this.schemaPath = schemaPath;
36 public Absolute getSchemaPath() {
40 private Object writeReplace() {
41 return new Proxy(this);
45 public String toString() {
46 return "SchemaPathMessage [schemaPath=" + schemaPath + "]";
49 private static class Proxy implements Externalizable {
50 private static final long serialVersionUID = 2L;
52 private SchemaPathMessage schemaPathMessage;
54 @SuppressWarnings("checkstyle:RedundantModifier")
56 //due to Externalizable
59 Proxy(final SchemaPathMessage schemaPathMessage) {
60 this.schemaPathMessage = schemaPathMessage;
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);
72 out.writeBoolean(true);
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();
83 final boolean absolute = in.readBoolean();
85 throw new InvalidObjectException("Non-absolute path");
87 schemaPathMessage = new SchemaPathMessage(Absolute.of(paths));
90 private Object readResolve() {
91 return schemaPathMessage;