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 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;
20 public class SchemaPathMessage implements Serializable {
21 private static final long serialVersionUID = 1L;
23 private SchemaPath schemaPath;
25 public SchemaPathMessage(final SchemaPath schemaPath) {
26 this.schemaPath = schemaPath;
29 public SchemaPath getSchemaPath() {
33 private Object writeReplace() {
34 return new Proxy(this);
37 private static class Proxy implements Externalizable {
38 private static final long serialVersionUID = 2L;
40 private SchemaPathMessage schemaPathMessage;
43 //due to Externalizable
46 Proxy(final SchemaPathMessage schemaPathMessage) {
47 this.schemaPathMessage = schemaPathMessage;
51 public void writeExternal(final ObjectOutput out) throws IOException {
52 out.writeInt(Iterables.size(schemaPathMessage.getSchemaPath().getPathTowardsRoot()));
54 for (final QName qualifiedName : schemaPathMessage.getSchemaPath().getPathTowardsRoot()) {
55 out.writeObject(qualifiedName);
58 out.writeBoolean(schemaPathMessage.getSchemaPath().isAbsolute());
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();
68 final boolean absolute = in.readBoolean();
69 schemaPathMessage = new SchemaPathMessage(SchemaPath.create(absolute, paths));
72 private Object readResolve() {
73 return schemaPathMessage;