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);
39 private static class Proxy implements Externalizable {
40 private static final long serialVersionUID = 2L;
42 private SchemaPathMessage schemaPathMessage;
44 @SuppressWarnings("checkstyle:RedundantModifier")
46 //due to Externalizable
49 Proxy(final SchemaPathMessage schemaPathMessage) {
50 this.schemaPathMessage = schemaPathMessage;
54 public void writeExternal(final ObjectOutput out) throws IOException {
55 out.writeInt(Iterables.size(schemaPathMessage.getSchemaPath().getPathTowardsRoot()));
57 for (final QName qualifiedName : schemaPathMessage.getSchemaPath().getPathTowardsRoot()) {
58 out.writeObject(qualifiedName);
61 out.writeBoolean(schemaPathMessage.getSchemaPath().isAbsolute());
65 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
66 final int sizePath = in.readInt();
67 final QName[] paths = new QName[sizePath];
68 for (int i = 0; i < sizePath; i++) {
69 paths[i] = (QName) in.readObject();
71 final boolean absolute = in.readBoolean();
72 schemaPathMessage = new SchemaPathMessage(SchemaPath.create(absolute, paths));
75 private Object readResolve() {
76 return schemaPathMessage;